[R] question about if else

Svetlana Eden svetlana.eden at vanderbilt.edu
Fri Feb 27 19:12:21 CET 2004


Today is a good day for asking question, I guess.

> c()
NULL
>
> length(c())==0
[1] TRUE
>
> r = ifelse(length(c())!=0, c(), c(1,2))  ### OK
> r = c()                                  ### OK
> r = ifelse(length(c())==0, c(), c(1,2))  ### why this is not OK (given
> the previous two)?       
Error in "[<-"(`*tmp*`, test, value = rep(yes, length =
length(ans))[test]) :
        incompatible types
>
> c() == NULL
logical(0)
>
> r = ifelse(c()==NULL, c(), c(1,2))       ### why this line does not 
> r                                        ### result in error -
logical(0)                                 ### 'c()==NULL' is not TRUE
and not FALSE ?
>
>

-- 
Svetlana Eden        Biostatistician II            School of Medicine
                     Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list