我有以下数据集
id1<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
status<-c(1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2)
df<-data.frame(id1,status)
In df
我观察到的 40%status
是“2”。
我正在寻找一个函数来提取 10 个观察值的样本df
同时保持上述比例。
我已经看过了R中数据帧的分层随机抽样 https://stackoverflow.com/questions/23479512/stratified-random-sampling-from-data-frame-in-r但它并不是在谈论比例。