I am trying to create a test dataset and a train data set from a list. I randomly take 20% of the data as my test set, now I need to put the rest of the 80% into my training dataset. How can I do that?
I have now tried: let "index" be the index of my 20% selected data for testing, and -index be the 80% (which is not working)
ntest = round(3081*0.2)
index = sample(3081, ntest, replace = FALSE)
traindata=m[-index,]
testdata=m[index,]
(this part is working but when I check the traindata it gives me data from the beginning of the list: 1,2,3,4... instead of the rest of the index which are not selected to be in the test set.)
My expected result would be testdata giving me 20% of the elements from the list and traindata giving me the rest of the 80%. Thank you very much.
Aucun commentaire:
Enregistrer un commentaire