The which() function help page states that, in the default case, what the 
function returns  is:
" Basically, the result is (1:length(x))[x]."
That would only be true if there are not any NA values in x. I think it would 
be more accurate to say:
"Basically, the result is (1:length(x))[!is.na(x) & x]."

The "strange" (IMHO) behavior of logical indexing in R makes it necessary to 
exclude NA values.
For this reason, I  use to wrap logical indices with  which(). I would have 
written the above expression as:
(1:length(x))[which(x)]
But that would have been a really bad explanation of how the which() function 
works ;)

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to