Skip to content

Instantly share code, notes, and snippets.

@nassimhaddad
Last active December 11, 2015 03:39
Show Gist options
  • Save nassimhaddad/4539363 to your computer and use it in GitHub Desktop.
Save nassimhaddad/4539363 to your computer and use it in GitHub Desktop.
Sampling with probability distribution
# generate example:
prob <- c(2, rep(1,9))
v <- vector()
for (i in 1:10000){
v <- c(v, sample(1:10, 1, prob = prob))
}
# print the output:
print(table(v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment