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