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