I have a dataset from a follow up study with before and after values for various tests (test "A", "B", and so on; up to 20 tests performed). The data frame is arranged so that "pre" and “post” are separated as in TABLE 1:
Group| A_pre | B_pre | A_post | B_post
0 20 20 21 23
1 30 19 10 11
2 10 30 53 34
1 22 25 32 20
2 34 32 40 30
0 30 NA 50 40
0 39 19 40 20
1 40 20 NA 20
2 50 20 10 10
0 34 30 23 10
I would like the data for each test (A and B) to be reordered so that "pre" and "post" are adjacent as below TABLE 2:
Group| A_pre | A_post | B_pre | B_post
0 20 21 20 23
1 30 10 19 11
2 10 53 30 34
1 22 32 25 20
2 34 40 32 30
0 30 50 NA 40
0 39 40 19 20
1 40 NA 20 20
2 50 10 20 10
0 34 23 30 10
I have tried using match
and rbind
but I haven't been successful. I am hoping to avoid using excel and VLOOKup, as they are error prone.