[R] ifelse when test is shorter than yes/no

Liaw, Andy andy_liaw at merck.com
Thu May 20 23:19:44 CEST 2004


> From: Vadim Ogranovich
> 
> Hi,
>  
> It turns out that the 'test' vector in ifelse(test, yes, no) is not
> recycled if it is shorter than the other arguments, e.g.
>  
> > ifelse(TRUE, seq(10), -seq(10))
> [1] 1
> 
>  
> Is there any particular reason it is not recycled? If there is one
> indeed a warning message might be in order when someone calls ifelse
> with a shorter 'test'.

?ifelse says:

Value:

     A vector of the same length and attributes (including class) as
     'test' and data values from the values of 'yes' or 'no'.  ...

Seems to me it works as documented.  Why do you expected otherwise?

Andy
  
> This is R1.8.1 on RH-7.3
>  
> Thanks,
> Vadim
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list