[R] 1 not equal to 1, and rep command
Daniel Nordlund
djnordlund at frontier.com
Mon Sep 12 19:01:57 CEST 2011
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Benjamin Høyer
> Sent: Monday, September 12, 2011 6:19 AM
> To: r-help at r-project.org
> Cc: tapo at novozymes.com
> Subject: [R] 1 not equal to 1, and rep command
>
> Hi
>
> I need to use rep() to get a vector out, but I have spotted something very
> strange. See the reproducible example below.
>
> N <- 79
> seg <- 5
> segN <- N / seg # = 15.8
>
> d1 <- seg - ( segN - floor(segN) ) * seg
> d1 # = 1
Not on my machine.
> d1-1
[1] -3.552714e-15
See FAQ 7.31
>
> rep(2, d1) # = numeric(0), strange - why doesn't it print one
> d1-1
[1] -3.552714e-15
<<<snip>>>
>
>
> Seems like there's some binary maths errors here somewhere. Very strange
> to
> me. Anyway, I need to be able to use the result d1 in a rep() command.
> Any
> way to force rep not to be *too* specific in how it reads its "times"
> argument?
Maybe round() will work for you, since you seem to be expecting a whole number.
rep(2, round(d1))
Hope this is helpful.
Dan
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list