df <- data.frame(
treat_1 = c("control", "treatment", "placebo"),
treat_2 = c("treatment", "placebo", "control"),
treat_3 = c("placebo", "control", "treatment"),
condition_a = c("A", "B", "A"),
condition_b = c("B", "A", "B"),
id = 1:3
)
set.seed(1037)
# Mask one set of variables
library(dplyr)
df |> mask_variables_rowwise(starts_with("treat_"))
# Using character vectors
df |> mask_variables_rowwise(c("treat_1", "treat_2", "treat_3"))
# Mask multiple sets separately
df |>
mask_variables_rowwise(starts_with("treat_")) |>
mask_variables_rowwise(c("condition_a", "condition_b"))
# Example with custom prefix
df |> mask_variables_rowwise(starts_with("treat_"), prefix = "group_")
Run the code above in your browser using DataLab