Hi all...

My students were conflating grepping for a value in a vector to get the
index, and then removing it with [-index], for instance like this:

set.seed(17)
v <- rnorm(20)
s <- v[-1.18]

They were trying to remove the 12th value in v, which is -1.18 or so.

But the result is, as documented in ?Extract, to coerce 1.18 to the next
lowest integer, and remove the 1st value of v, not the 12th value.

This strikes me as something that ought to give an error or warning, or at
least be in the R Inferno, but I couldn't find it there.

Under what circumstances would the documented behavior be valuable?  I can
see that it avoids doing floor or as.integer in computations where an index
is needed but real numbers are generated for whatever reason, but is that
common?

Thanks for any insight.  Bryan
*************
Bryan Hanson
Acting Chair
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA

______________________________________________
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.

Reply via email to