Hi, I have used the function choose(n, k) sometimes, and i realized that it doesn't work properly for n < 0. For example, if one tries choose(-1, 3), it should be returned the value (-1)^3 = -1, since choose (-1, 3) = (-1)*(-2)*(-3)/3! = (-1)^3, but indeed R returns the value 0. I am using R version 2.5.1, it don't know if this little bug has already been solved in the new version. Thanks, Luis Ernesto. --------------------------------- [[alternative HTML version deleted]]
well, choose(n, k) should actually return: factorial(n)/(factorial(n-k)*factorial(k)) R-2.6.0 works just fine for me.... so does R-2.5.1.... so does R-2.4.1.... b On Nov 22, 2007, at 8:04 PM, Luis Salasar wrote:> Hi, > > I have used the function choose(n, k) sometimes, and i realized > that it doesn't work properly for n < 0. For example, if one tries > choose(-1, 3), it should be returned the value (-1)^3 = -1, since > choose (-1, 3) = (-1)*(-2)*(-3)/3! = (-1)^3, but indeed R returns > the value 0. I am using R version 2.5.1, it don't know if this > little bug has already been solved in the new version. Thanks, > > Luis Ernesto. > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 22/11/2007 8:04 PM, Luis Salasar wrote:> Hi, > > I have used the function choose(n, k) sometimes, and i realized that it doesn't work properly for n < 0. For example, if one tries choose(-1, 3), it should be returned the value (-1)^3 = -1, since choose (-1, 3) = (-1)*(-2)*(-3)/3! = (-1)^3, but indeed R returns the value 0. I am using R version 2.5.1, it don't know if this little bug has already been solved in the new version. Thanks,You're right. There's some code to optimize the k <= 30 case and it doesn't take n < 0 into account. I'll fix it. Duncan Murdoch