I try to figure out how dose the sample function work when I try to random select 10 samples in each group from the data frame.
I have a data frame with 5 columns and 7000 rows. I split the dataset into around 200 groups. Then I want to random select 10 samples from each group. Some groups have less 10 samples. So when I try to sample them, I set replace=T. However, when I check the output, I found out some groups which were more then 10 sample in the group have repeat samples.
I am not sure how to fix this?
mydata2<- split(mydf,mydf$Group)
names(mydata2)<-paste0("mydata2",1:length(levels(mydf$Group)))
mysample<-Map(function(x) x[sample((1:nrow(x)),size=10,replace=T),],
mydata2)
Aucun commentaire:
Enregistrer un commentaire