I have searched and found a number of examples, so far I have not been able to solve a problem in transforming my data from wide to long.
Below is an example of the data:
set.seed(12345)
id = 1:100
age = sample(1:100, 100, replace=TRUE)
group = sample(1:2, 100, replace=TRUE)
t0_var1 = sample(1:300, 100, replace=TRUE)
t2_var1 = sample(1:300, 100, replace=TRUE)
t0_var2 = sample(1:600, 100, replace=TRUE)
t2_var2 = sample(1:600, 100, replace=TRUE)
t0_var3 = sample(1:700, 100, replace=TRUE)
t2_var3 = sample(1:700, 100, replace=TRUE)
dataset = data.frame(id, age, group, t0_var1, t2_var1, t0_var2, t2_var2, t0_var3, t2_var3)
head(dataset)
id age group t0_var1 t2_var1 t0_var2 t2_var2 t0_var3 t2_var3
1 1 73 1 177 16 46 126 490 431
2 2 88 2 268 180 285 460 8 250
3 3 77 2 38 213 159 505 353 326
4 4 89 2 154 197 139 561 512 210
5 5 46 2 200 174 358 406 231 50
6 6 17 2 230 204 96 516 575 506
I need the columns to be arranged as follows:
id | age | group | assessment | var1 | var2 | var3
1 | 23 1 1 12 34 64
1 | 23 1 2 34 14 68
2 | 43 2 1 22 44 54
2 | 43 2 2 34 54 88
...
I tried in different ways, but I'm only managing to transform two columns at a time.
Thanks in advance for your help.