This function takes a data frame and adds a new column named "treated" with randomly assigned TRUE/FALSE values. Randomization can be done either on the entire data frame or stratified by specified columns. The probability of being assigned to the treatment group can be specified, with a default of 0.5.
.randomize_internal(data, group_by = NULL, seed = NULL, pr_treated = 0.5)
A new data frame with the added "treated" column.
The input data frame.
(Optional) A character vector of column names to stratify the randomization. If provided, the randomization will be done within d each groupefined by the specified columns.
(Optional) An integer to set the random seed for reproducibility.
(Optional) The probability of a row being assigned to the treatment group (TRUE). Default is 0.5.