Created
September 8, 2013 14:28
-
-
Save davetang/6485110 to your computer and use it in GitHub Desktop.
Calculating the number of permutations without repetition/replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install if necessary | |
install.packages('gtools') | |
#load library | |
library(gtools) | |
#urn with 3 balls | |
x <- c('red', 'blue', 'black') | |
#pick 2 balls from the urn with replacement | |
#get all permutations | |
permutations(n=3,r=2,v=x) | |
# [,1] [,2] | |
#[1,] "black" "blue" | |
#[2,] "black" "red" | |
#[3,] "blue" "black" | |
#[4,] "blue" "red" | |
#[5,] "red" "black" | |
#[6,] "red" "blue" | |
#number of permutations | |
nrow(permutations(n=3,r=2,v=x)) | |
#[1] 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment