Skip to content
Prev 177574 / 398506 Next

Including a vector element in an if statement

On Apr 19, 2009, at 5:58 PM, Enda Hargaden wrote:

            
See below. the 'if' control construct is not set up to accept vectors.
 From the help page ?"if"
if(cond) expr
Arguments
cond 	A length-one logical vector that is not NA.
Jim gave you a perfectly workable solution, but you might find it  
instructive to review the difference between "if" and the function  
"ifelse". Generally "if" will not be useful in situations where you  
are doing comparisons on indexed objects whereas that is precisely  
what "ifelse" is designed to do. (Tthis was also pointed out in a  
response to a question earlier today.)


David Winsemius, MD
Heritage Laboratories
West Hartford, CT