> -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Benjamin Høyer > Sent: Monday, September 12, 2011 6:19 AM > To: r-help@r-project.org > Cc: t...@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 ______________________________________________ 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.