Randomly sample data frame into 3 groups in R
问题 Objective: Randomly divide a data frame into 3 samples. one sample with 60% of the rows other two samples with 20% of the rows samples should not have duplicates of others (i.e. sample without replacement). Here's a clunky solution: allrows <- 1:nrow(mtcars) set.seed(7) trainrows <- sample(allrows, replace = F, size = 0.6*length(allrows)) test_cvrows <- allrows[-trainrows] testrows <- sample(test_cvrows, replace=F, size = 0.5*length(test_cvrows)) cvrows <- test_cvrows[-which(test_cvrows %in%