[Rd] negative numerics in []

Michael Haupt michael.haupt at oracle.com
Thu Sep 4 17:17:16 CEST 2014


Hello,

I'm a bit puzzled by what looks (to me) like a discrepancy between documentation and implementation.

The documentation for [] says this about the indices: "Numeric values are coerced to integer as by as.integer (and hence truncated towards zero)."

> as.integer(-3.1)
[1] -3

Good. But:

> x <- c(1,2,3)
> x[-3.1]
[1] 1 2 3

Given the documentation, I'd have expected a result of "[1] 1 2", because -3.1 should be coerced to -3 (by virtue of as.integer).

What bit do I not get? (I'm using R 3.1.1, if that matters.)

Best,

Michael

-- 
Dr. Michael Haupt
Principal Member of Technical Staff
Phone: +49 331 200 7277, Fax: +49 331 200 7561
Oracle Labs
Oracle Deutschland B.V. & Co. KG, Schiffbauergasse 14, 14467 Potsdam, Germany



More information about the R-devel mailing list