jeudi 20 août 2015

Shuffle the rows of a data frame to obtain 10 shuffled data frames

I have a data frame with 12 continuous variables and one grouping categorical response factor, containing two classes (G8 and V4). I want to shuffle the rows in the data frame 10 times, so I acquire 10 different variations of the data frame to test. I want to use each version of the data frame to test a classifier algorithm. The code I am using is:-

Data(LDA.scores)

shuffle.cross.validation<-LDA.scores[sample(nrow(LDA.scores[2:13])),]

However, when I use this code, the categorical response factor strings transform into zero values when the data frame is shuffled. This defeats the object because the response variable is the grouping factor to classify the continuous variables. Thank you if anyone has a solution.




Aucun commentaire:

Enregistrer un commentaire