mercredi 12 février 2020

R: How to randomly sample one value from each column and bootstrap

I have 18 columns and 100 rows, where columns stand for 18 students and rows stand for their grades in 100 exams. Here is what I want: for each student, I want to randomly sample/select only one grade from all 100 grades. In other words, I want a sample with 18 columns and just 1 row. I have tried apply, sample functions, but all of these just don't work, and I don't know why. Any help would be greatly appreciated! Thank you so much!

bs = data.frame(matrix(nrow=1,ncol=18))
for (i in colnames(high)){
  bs[,i]=sample(high[,i],1,replace=TRUE)
}

as.data.frame(lapply(high[,i],sample,18,replace=TRUE))



Aucun commentaire:

Enregistrer un commentaire