lundi 19 octobre 2020

How can I make many samples from a specific population in R?

I have this population:

MyPopulation <- c(1:100)

and I want to create a data frame of 40 columns and 5 lines. Each column has to be a random sample of MyPopulation, so I try this:

MySample <- data.frame(NoSample = c(1:5))

for (i in 1:40) {
  MySample$i <- sample(MyPopulation,5)
}

The result is a data frame with only 1 more column (named i) with a random sample as values.

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire