R 将虚拟列添加到标志中,因为行是随机选择的或不是随机选择的
假设我有以下数据集(名为R 将虚拟列添加到标志中,因为行是随机选择的或不是随机选择的,r,sampling,R,Sampling,假设我有以下数据集(名为data) 我的意图是向原始数据集添加一个新列,指示是否随机选择了数据集的每一行(1/0)。我尝试了以下方法 library(sampling) data1 <- strata(data,"var1", size=c(4,3),method="srswor") #stratified random sampling data2 <- getdata(data,data1) # this gives a separate
data
)
我的意图是向原始数据集添加一个新列,指示是否随机选择了数据集的每一行(1/0)。我尝试了以下方法
library(sampling)
data1 <- strata(data,"var1", size=c(4,3),method="srswor") #stratified random sampling
data2 <- getdata(data,data1) # this gives a separate data set
库(采样)
数据1如果查看sampling::strata()
的文档,您会发现以下信息:
The function produces an object, which contains the following information:
ID_unit
the identifier of the selected units.
Stratum
the unit stratum.
Prob
the unit inclusion probability.
ID_单元可用于对原始数据进行子集划分,并指定所需的布尔值:
数据4 A 55正确
#>5 B 22错误
#>6 A 33正确
#>7 B 90正确
#>8 A 78正确
#>9 B 12正确
#>10 A 11正确
由(v0.3.0)于2020-07-28创建您能用dput(数据)的输出替换您的数据样本吗?使复制您的示例更容易。。。
The function produces an object, which contains the following information:
ID_unit
the identifier of the selected units.
Stratum
the unit stratum.
Prob
the unit inclusion probability.