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 want to use trunc, round, floor or ceiling  
depending on what you want to achieve.  Personally, I would be tempted  
to do the integer conversion in one step and then do the balance with  
integers.

p <- 0.34
pb <- trunc(p*100)
pr <- 100 - pb

There is a FAQ ("7.31 Why doesn't R think these numbers are equal?")  
that sheds light on this...

http://cran.r-project.org/doc/FAQ/R-FAQ.html

Cheers,
Ben

> 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 anyone help me? Thanks in  
> advance.
>
> Paolo
>
> ______________________________________________
> 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.


	[[alternative HTML version deleted]]

