[R] ! arithmetic

Thomas Lumley tlumley at u.washington.edu
Mon Feb 17 19:17:03 CET 2003


On Sat, 15 Feb 2003, Stan Markus wrote:

>
> Since "!" is a logical operator in R, how does one use it in its
> arithmetic sense, say to calculate x!/y!(N-y)! ?
>

- You can use gamma(x+1) for factorial, or the factorial() function in the
"gregmisc" package
- More usefully, you can use lgamma(x+1) to compute log factorials and
reduce overflow problems if any of the numbers is large
- It's also worth looking at choose() and lchoose() , which compute the
binomial coefficients and their logarithms.

	-thomas




More information about the R-help mailing list