df <- data.frame(
day_1 = c(1, 4, 7),
day_2 = c(2, 5, 8),
day_3 = c(3, 6, 9),
score_a = c(10, 40, 70),
score_b = c(20, 50, 80),
id = 1:3
)
set.seed(123)
# Scramble one set of variables
library(dplyr)
df |> scramble_variables_rowwise(starts_with("day_"))
# Using character vectors
df |> scramble_variables_rowwise(c("day_1", "day_2", "day_3"))
# Scramble multiple sets separately
df |>
scramble_variables_rowwise(starts_with("day_")) |>
scramble_variables_rowwise(c("score_a", "score_b"))
# Multiple selectors are combined into one set (values can move between day_* and score_*)
df |> scramble_variables_rowwise(starts_with("day_"), starts_with("score_"))
Run the code above in your browser using DataLab