有许多实现数据分区的方法。要获得更完整的方法,请查看createDataPartition函数中的caret包裹。下面是一个简单的例子:data(mtcars)## 75% of the sample sizesmp_size <- floor(0.75 * nrow(mtcars))## set the seed to make your partition reproducibleset.seed(123)train_ind <- sample(seq_len(nrow(mtcars)), size = smp_size)train <- mtcars[train_ind, ]test <- mtcars[-train_ind, ]