R 随机抽取样本

R 随机抽取样本,r,random,R,Random,我想偶然选择x样本(其中x==2)是我的数据帧df: sample_id no State NLABfather NE001 chr7-42751387-42759372-1n 1n <NA> NE001 chr4-106417821-106429609-3n 3n <NA> NE002 chr28-2568550-2572925-3n 3n

我想偶然选择
x
样本(其中
x==2
)是我的数据帧
df

sample_id           no                 State  NLABfather
NE001      chr7-42751387-42759372-1n    1n       <NA>
NE001    chr4-106417821-106429609-3n    3n       <NA>
NE002       chr28-2568550-2572925-3n    3n       <NA>
NE002     chr23-27707672-27707672-3n    3n       <NA>
NE003       chr25-1157646-1170719-1n    1n       <NA>
NE003     chr21-20145005-20155775-0n    0n       <NA>

多谢各位

子集(df,sample\u id%在%sample(unique(sample\u id),2)中)如何??

或者如果没有子集函数,您可以执行以下操作: df[样品(c(1:nrow(df)),2),]

sample_id           no                 State  NLABfather
NE001      chr7-42751387-42759372-1n    1n       <NA>
NE001    chr4-106417821-106429609-3n    3n       <NA>
NE002       chr28-2568550-2572925-3n    3n       <NA>
NE002     chr23-27707672-27707672-3n    3n       <NA>