[R] choose() function returning anomalous results (zero instead of one)
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Sep 6 21:02:12 CEST 2012
On 06/09/2012 2:09 PM, Shayne Hodge wrote:
> Hello,
>
> (Apologies for length, wanted to get all the relevant detail in that I know
> of).
>
> I've been having a lot of trouble with some code for an inventory analysis
> problem I was doing, and finally came to the conclusion that it appears
> that choose() is returning incorrect values. Specifically:
>
> -------------
>
> Browse[1]> nn
> [1] 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3
> Browse[1]> Q1
> [1] 3
> Browse[1]> choose(Q1,3)
> [1] 0
That's easy to reproduce, with correct behaviour:
> Q1 <- 3 - 1e-10
> Q1
[1] 3
> choose(Q1, 3)
[1] 0
My guess is your code (which is tl;dr) computes Q1 with some rounding
error, and you're seeing something like this.
Duncan Murdoch
More information about the R-help
mailing list