Created
September 9, 2013 02:43
-
-
Save davetang/6490917 to your computer and use it in GitHub Desktop.
Calculate the number of combinations with 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
comb_with_replacement <- function(n, r){ | |
return( factorial(n + r - 1) / (factorial(r) * factorial(n - 1)) ) | |
} | |
#have 3 elements, choosing 3 | |
comb_with_replacement(3,3) | |
#[1] 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment