Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

N Choose K function in R not working--what am I missing?

Tags:

r

I was trying to acquaint myself with R's nChooseK function but I can't get it to work. I thought it was part of the standard setup (i.e. no additional package needed).

Please help. Here is what I tried:

> nChooseK(10,2) 
  Error: could not find function "nChooseK"
> n<-4;k<-2
> print(nChooseK(n,k)) 
 Error in print(nChooseK(n, k)) : could not find function "nChooseK"

the last one was an example I saw here: R basic nChooseK

like image 864
daniellopez46 Avatar asked May 16 '12 18:05

daniellopez46


2 Answers

The function is in the R.basic package which is not part of the default R installation. You probably meant to use just choose().

like image 153
joran Avatar answered Nov 15 '22 07:11

joran


As joran mentions the function nChooseK is a part of R.basic. You can tell this from the example you posted by looking at the top of the page:


Rbasic Page


You'll notice the "R.basic" in the curley braces which tells you that that function is a part of the "R.basic" package. So to use nChooseK you'll first need to load that package

library(R.basic)

If you don't have R.basic installed yet then you'll need to install it

install.packages("R.basic", contriburl="http://www.braju.com/R/repos/")
library(R.basic)

But as noted the choose function in base R does the same thing

choose(37, 12)
#[1] 1852482996
nChooseK(37, 12)
#[1] 1852482996
like image 34
Dason Avatar answered Nov 15 '22 09:11

Dason