分层随机分配:修复错误

时间:2019-02-22 17:19:05

标签: r random variable-assignment

library(data.table)

foo = setDT(your.data.frame) # transform your df into a data.table

dat = foo[, .SD[sample(.N, round(.N * 0.5))], by = BCS] # sample 50% of rows of each BCS

foo[subject %in% dat[, .(subject), status := "treatment"][is.na(status), status:= "control"] # assign a control treatment column

在上面的R代码中,请问有人知道为什么最后一行代码不起作用吗?即:foo[subject %in% dat[, .(subject), status := "treatment"][is.na(status), status:= "control"] # assign a control treatment column

0 个答案:

没有答案