Re: [R] function rep

2010-04-09 Thread Ben Tupper
Hi, On Apr 9, 2010, at 4:58 PM, Covelli Paolo wrote: > Hi, > > I've got the following code: > > p <- 0.34 > pb <- p*100 > pr <- (1-p)*100 > I think you are bumping into the issue that most numbers can't be exactly expressed digitally. Your variable, pr, isn't exactly the 66 you think it is.

Re: [R] function rep

2010-04-09 Thread RICHARD M. HEIBERGER
Covelli, From ?rep Non-integer values of times will be truncated towards zero. If times is a computed quantity it is prudent to add a small fuzz. Thus, the example is a very interesting special case of FAQ 7.31, > sprintf("%17.17a",66) [1] "0x1.08000p+6" > sprintf("%17.17a",pr) [1]

Re: [R] function rep

2010-04-09 Thread Stephan Kolassa
Hi, this is FAQ 7.31: pb and pr are floating-point numbers that are coerced to integer for rep(), and this does not always work the way you want. HTH Stephan Covelli Paolo schrieb: Hi, I've got the following code: p <- 0.34 pb <- p*100 pr <- (1-p)*100 A <- rep(0,pb) # a vector with 34 "

Re: [R] function rep

2010-04-09 Thread Henrique Dallazuanna
See FAQ "7.31 Why doesn't R think these numbers are equal?" and try this: rep(1, ceiling(pr)) On Fri, Apr 9, 2010 at 5:58 PM, Covelli Paolo wrote: > Hi, > > I've got the following code: > > p <- 0.34 > pb <- p*100 > pr <- (1-p)*100 > > A <- rep(0,pb)  # a vector with 34 "zeros" > B <- rep(1,pr)

Re: [R] function rep

2010-04-09 Thread Gang Liang
pr is a numeric number indeed slightly less than 66, hence, the vector generated by rep(1,pr) is of length 65 rather than 66... On Fri, Apr 9, 2010 at 1:58 PM, Covelli Paolo wrote: > Hi, > > I've got the following code: > > p <- 0.34 > pb <- p*100 > pr <- (1-p)*100 > > A <- rep(0,pb) # a vect

Re: [R] function rep

2010-04-09 Thread Erik Iverson
Hello, Covelli Paolo wrote: Hi, I've got the following code: p <- 0.34 pb <- p*100 pr <- (1-p)*100 A <- rep(0,pb) # a vector with 34 "zeros" B <- rep(1,pr) # a vector with 66 "ones" Not true. I counted them myself. There are only 65. I see > pr == 66 [1] FALSE > pr < 66 [1] TRUE So