I\'ve just started using R and I\'m not sure how to incorporate my dataset with the following sample code:
sample(x, size, replace = FALSE, prob = NULL)
My solution is basically the same as dickoa's but a little easier to interpret:
data(mtcars) n = nrow(mtcars) trainIndex = sample(1:n, size = round(0.7*n), replace=FALSE) train = mtcars[trainIndex ,] test = mtcars[-trainIndex ,]