I have a data set called data
, which I am splitting into 2 new data sets, which I will call test
and train
.
I want the splitting to be random, without replacement.
Using the code below, I get train
to be a new data frame with 35 elements:
rows_in_test <- 35 # number of rows to randomly select
rows_in_train <- nrow(data) - rows_in_test
train <- data[sample(nrow(data), rows_in_test), ]
Is there a nice way in R to assign the complement of train
to a new data set called test
? I am thinking there must be a function for this?