[R] How to subset my data and at the same time keep the balance?

Eddie Smith eddieatr at gmail.com
Mon Nov 19 20:07:58 CET 2012


Thanks a lot! I got some ideas from all the replies and here is the final one.

newdata

select <- sample(nrow(newdata), nrow(newdata) * .7)
data70 <- newdata[select,]  # select
write.csv(data70, "data70.csv", row.names=FALSE)

data30 <- newdata[-select,]  # testing
write.csv(data30, "data30.csv", row.names=FALSE)

Cheers




More information about the R-help mailing list