vendredi 22 février 2019

Stratified random assignment: Fix bug

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

In the R code above, Please, does any one know why the last line of code is not working? That is: foo[subject %in% dat[, .(subject), status := "treatment"][is.na(status), status:= "control"] # assign a control treatment column




Aucun commentaire:

Enregistrer un commentaire