On Fri, Mar 26, 2010 at 4:15 PM, Matthew Dowle <mdo...@mdowle.plus.com> wrote: > The type of 'NA' is logical. So x[NA] behaves more like x[TRUE] i.e. silent > recycling. > >> class(NA) > [1] "logical" >> x=101:108 >> x[NA] > [1] NA NA NA NA NA NA NA NA >> x[c(TRUE,NA)] > [1] 101 NA 103 NA 105 NA 107 NA > >> x[as.integer(NA)] > [1] NA > > HTH
Ouch. What is happening is that a numeric vector containing NA has become a logical vector of all NA because "‘NA’ is a logical constant of length 1" [?NA] Obviously R doesn't know that my c(NA,NA) came from c(4,NA,NA) and not c(TRUE,NA,NA). And it prints them the same: > NA_integer_ [1] NA > NA [1] NA Oh well, one to remember. I've got an urge to go eat a baNANA now. Barry ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.