Skip to content

Instantly share code, notes, and snippets.

@davetang
Created September 9, 2013 02:43
Show Gist options
  • Save davetang/6490917 to your computer and use it in GitHub Desktop.
Save davetang/6490917 to your computer and use it in GitHub Desktop.
Calculate the number of combinations with replacement
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