[Rd] negative numerics in []

Bryan Hanson hanson at depauw.edu
Thu Sep 4 20:47:34 CEST 2014


Just for the sake of completeness, I raised a closely related issue back in 2010 which my students discovered.

https://stat.ethz.ch/pipermail/r-help/2010-March/231788.html

Bryan

On Sep 4, 2014, at 11:17 AM, Michael Haupt <michael.haupt at oracle.com> wrote:

> 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
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list