I would suggest using dplyr and filter with an anti_join
Start with the total data. Filter by whatever determines the training or test.
then anti-join the training data from the total data leaving the test.data
To do it randomly, you can use something like
library(dplyr)
total.data <- data.frame(x=c(1:5), y=c(6:10))
total.data <- mutate(total.data, Pick.Me = sample(c(0,1), size=dim(total.data)[[1]], replace=TRUE, prob=c(0.7,0.3)))
training.data <- filter(total.data, Pick.Me==0)
test.data <- anti_join(total.data, training.data)