A base R option with reshape
reshape(
setNames(test,gsub("(\d)(.)","\2.\1",names(test))),
direction = "long",
idvar = c("id","name"),
varying = -(1:2)
)
gives
id name time variable_a variable_b
1.a.1 1 a 1 1 5
2.b.1 2 b 1 2 6
3.c.1 3 c 1 3 7
4.d.1 4 d 1 4 8
1.a.2 1 a 2 9 13
2.b.2 2 b 2 10 14
3.c.2 3 c 2 11 15
4.d.2 4 d 2 12 16
1.a.3 1 a 3 17 21
2.b.3 2 b 3 18 22
3.c.3 3 c 3 19 23
4.d.3 4 d 3 20 24
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…