0
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

4

0 回答 0