Suppose I want to create a sample of N elements chosen from [1,2,3] such that 1, 2 and 3 will be represented with weights 0.4,0.4 and 0.2 respectively. How would I do this.
I know how to do it in R without using loops:
mySample <- sample(c(1,2,3),size = 100,replace=T,prob = c(.4,.4,.2))
Aucun commentaire:
Enregistrer un commentaire