Maxim Veksler Maxim Veksler -4 years ago 144
R Question

How to calculate combination and permutation in R?

I just started to learn Probability, and I'm looking for tools to work with on linux.

I've found some Combinations packages http://rss.acs.unt.edu/Rdoc/library/Combinations/html/00Index.html but when I tried to install them, the process failled with the following message:

> install.packages("Combinations")
Installing package(s) into ‘/home/maxim/R/x86_64-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘Combinations’ is not available (for R version 2.13.1)

Answer Source

You can use the combinat package with R 2.13:

install.packages("combinat")
require(combinat)
permn(3)
combn(3, 2)

If you want to know the number of combination/permutations, then check the size of the result, e.g.:

length(permn(3))
dim(combn(3,2))[2]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download