My data is set out similar to the example below where I have two columns as identifiers (vel
and var
) and six columns representing difference scores (diff_one
, diff_two
etc.) which I'd like to arrange from smallest to largest.
I know I can arrange one column by group as in the case below, but I'd like to arrange/sort all six difference columns from smallest to largest by the grouping variables vel
and var
. Is there a clean way to do this? Thanks.
set.seed(10)
dat <- data.frame(
vel = rep(c("slo", "med", "fas"), each = 28),
var = rep(paste0("var", 1:7), times = 12),
diff_one = rnorm(84, 0.03, 0.08),
diff_two = rnorm(84, 0.03, 0.08),
diff_three = rnorm(84, 0.03, 0.08),
diff_four = rnorm(84, 0.03, 0.08),
diff_five = rnorm(84, 0.03, 0.08),
diff_six = rnorm(84, 0.03, 0.08)
)
test <- dat %>%
filter(vel == "slo") %>%
group_by(vel, var) %>%
arrange(diff_one, .by_group = TRUE)