Given a situation like:
data.frame(x1 = 1:11, y1 = 3:13, x2 = 21:31, y2 = 4:14) |>
mutate(z1 = x1 + y1,
z2 = x2 + y2)
Resulting in:
x1 y1 x2 y2 z1 z2
1 1 3 21 4 4 25
2 2 4 22 5 6 27
3 3 5 23 6 8 29
4 4 6 24 7 10 31
5 5 7 25 8 12 33
6 6 8 26 9 14 35
7 7 9 27 10 16 37
8 8 10 28 11 18 39
9 9 11 29 12 20 41
10 10 12 30 13 22 43
11 11 13 31 14 24 45
Is there a way to calculate multiple variables (z1, z2, ...) based on the naming scheme (different prefixes [x, y, ...] and numeric suffixes [1, 2, ...])? I guess one possibility would be to transform the data frame into long format and back. But is there an other one?