[R] which() function help page precision
buzon informatica, ige
ige@inform@tic@ @ending from ige@eu
Fri Nov 16 11:08:58 CET 2018
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]]
More information about the R-help
mailing list