r语言:数据集分割.md 506 B


title: R语言:数据集分割 tags: [] id: '2267' categories:

  • - 数据清洗 date: 2022-08-19 20:48:06 ---

安装补充包

划分训练集和验证集

library("caTools")
dat <- readRDS('../data/dat.rds')
set.seed(123)
split = sample.split(substr(rownames(dat),1,2),SplitRatio = .8)
train_data = subset(dat, split == TRUE)
test_data  = subset(dat, split == FALSE)