anxiety_long <- anxiety_wide |>
pivot_longer(
cols = starts_with("anxiety_"),
names_to = "time",
values_to = "anxiety",
names_prefix = "anxiety_"
)
anxiety_long# A tibble: 15 × 4
participant_id condition time anxiety
<int> <chr> <chr> <dbl>
1 1 treatment t1 45
2 1 treatment t2 38
3 1 treatment t3 32
4 2 treatment t1 52
5 2 treatment t2 45
6 2 treatment t3 40
7 3 control t1 48
8 3 control t2 47
9 3 control t3 46
10 4 control t1 55
11 4 control t2 54
12 4 control t3 52
13 5 treatment t1 42
14 5 treatment t2 35
15 5 treatment t3 30
