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

16,636

Solution 1

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

Solution 2

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

Share:
16,636

Related videos on Youtube

daniellopez46
Author by

daniellopez46

Here to learn about R and data mining/predictive modeling. I am new to these topics but have a business and analytical background...

Updated on July 19, 2022

Comments

  • daniellopez46
    daniellopez46 almost 2 years

    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

    • Ben Bolker
      Ben Bolker about 12 years
      and as usual if you have no idea what package it's in you can (usually) use library(sos); findFn("nChooseK") (although this only finds it if it's on CRAN, not R-forge, Bioconductor etc.)

Related