s-news
[Top] [All Lists]

Re: 'Condition' statment

To: "Lambert.Winnie" <lambert.winnie@ensco.com>, "S-PLUS Newsgroup" <s-news@lists.biostat.wustl.edu>
Subject: Re: 'Condition' statment
From: Tony Plate <tplate@acm.org>
Date: Fri, 09 Jan 2004 14:30:58 -0700
In-reply-to: <8986151694190742869D08450EE4DCDE2459DE@amu-exch.ensco.win>
Reply-to: tplate@acm.org
'if' is not intended to accept vectors in the condition.  When given a vector, it uses only the first element to decide whether to execute the if or else block, and prints a warning to that effect:

> if (c(F)) T else F
[1] F
> if (c(T)) T else F
[1] T
> if (c(T,T)) T else F
Warning: Condition has 2 elements: only the first used: if(c(T, T)) T else F
[1] T
> if (c(T,F)) T else F
Warning: Condition has 2 elements: only the first used: if(c(T, F)) T else F
[1] T
> if (c(F,T)) T else F
Warning: Condition has 2 elements: only the first used: if(c(F, T)) T else F
[1] F
>

hope this helps,

Tony Plate


At Friday 04:08 PM 1/9/2004 -0500, Lambert.Winnie wrote:
All,
 
S-PLUS 6.0 R2, Windows XP
 
I have a scritp with nested IF algorithm in a WHILE loop:
 
...
iter <- iter+1
if (iter > 25)
{
    if ( abs(wsold[good] - wsnew[good] ) < wstol/10 )
    {
        goodc <- abs(wsnew[good] - w[good]) < 10*wstol
        tlcl[good][!goodc] <- NA
        plcl[good[!goodc} <- NA
        brk <- 1
    }
    else
    {
        tlcl[good] <- NA
        plcl[good] <- NA
        brk == 1
    }
}
if (brk == 1) break
...
 
Basically, if the specified condition in the while loop is not met after 25 iterations, the inner IF algorithm is invoked.  wsold, wsnew, w, tlcl, and plcl are vectors of the same length.  In one particular case where the vectors have a length of 92, 7 elements have not met the criteria necessary to end the WHILE loop and the nested IF statement is invoked.  Upon completion, I get the message
 
Condition has 7 elements: only the first used in: if(abs(wsold[good] - wsnew[good]) < wstol/10) { ....
 
Would someone mind telling me what this means?  A manual inspection revealed that all of the 7 elements met the condition in the nested IF statement and it appears that the commands under the IF statement were executed.  Thanks for any info you can provide.
 
Win Lambert

**********************************************
Winifred C. Lambert   Senior Scientist/Meteorologist
ENSCO, Inc.
Aerospace Sciences and Engineering Division
1980 N. Atlantic Ave., Suite 230
Cocoa Beach, FL  32931
VOICE: 321.853.8130  FAX: 321.853.8415
EMAIL: lambert.winifred@ensco.com

AMU Quarterly Reports are available online:
http://science.ksc.nasa.gov/amu/home.html
********************************************

 

Tony Plate   tplate@acm.org

<Prev in Thread] Current Thread [Next in Thread>