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
Now if I type
length(A), R answer correctly 34
but if I type
length(B), R answer 65 instead of 66.
I don't understand why it happens. Can
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 pr must not
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 pcove...@tele2.it wrote:
Hi,
I've got the following code:
p - 0.34
pb - p*100
pr - (1-p)*100
A - rep(0,pb) # a
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 pcove...@tele2.it 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)
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
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]
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. You'll
7 matches
Mail list logo