Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将虚拟列添加到标志中,因为行是随机选择的或不是随机选择的_R_Sampling - Fatal编程技术网

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.