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