R语言对dataframe(data.table)数据分层随机抽样实战
目录
R语言对dataframe(data.table)数据分层抽样实战
#仿真数据
set.seed(1)
n <- 1e4
d <- data.table(age = sample(1:5, n, T),
lc = rbinom(n, 1 , .5),
ants = rbinom(n, 1, .7))
> table(d$age, d$lc)
0 1
1 999 1001
2 1022 950
3 1008 936
4 1032 1005