[R] question about if else

Svetlana Eden
Fri, 27 Feb 2004 18:12:21 -0000

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