I have a dataframe (40 x 3, where rows is equal to number of people) and I want to randomly assign each person to one of 10 groups. In order to do that I created a new column called "group" and I did:
for (i in 1:dim(data)[1]) {data$group[i] = sample(1:10,1)}
Output:
Gr1  Gr2  Gr3  Gr4  Gr5  Gr6  Gr7  Gr8  Gr9 Gr10
 2    5    8    8    3    3    2    4    3    2
It works, but I would like to have almost the same number of individuals in each group. How can I do that? Thanks.
 
     
     
     
     
    