I am stuck trying to convert a df from long format to wide format. My data looks like this for one id (example 1102
; in the complete df there are many different ids:
>df_long[1:30,]
id roi mean sd timepoint
1 1102 HarvardOxford1 0.234243 0.1212333 A
2 1102 HarvardOxford2 0.111111 0.1212333 A
3 1102 HarvardOxford3 0.234243 0.1212333 A
4 1102 HarvardOxford4 0.111111 0.4657222 A
5 1102 Lh__F1_head 0.234243 0.1212333 A
6 1102 Lh__F2_body 0.534543 0.4657222 A
7 1102 Lh__F3_tail 0.234243 0.1212333 A
8 1102 Rh__F1_head 0.111111 0.4657222 A
9 1102 Rh__F2body 0.234243 0.1212333 A
10 1102 Rh__F3tail 0.111111 0.4657222 A
11 1102 HarvardOxford1 0.111111 0.1212333 B
12 1102 HarvardOxford2 0.234243 0.4657222 B
13 1102 HarvardOxford3 0.111111 0.4657222 B
14 1102 HarvardOxford4 0.111111 0.1212333 B
15 1102 Lh__F1_head 0.534543 0.4657222 B
16 1102 Lh__F2_body 0.234243 0.4657222 B
17 1102 Lh__F3_tail 0.234243 0.1212333 B
18 1102 Rh__F1_head 0.534543 0.4657222 B
19 1102 Rh__F2body 0.534543 0.4657222 B
20 1102 Rh__F3tail 0.234243 0.1212333 B
21 1102 HarvardOxford1 0.534543 0.4657222 C
22 1102 HarvardOxford2 0.234243 0.4657222 C
23 1102 HarvardOxford3 0.387666 0.4657222 C
24 1102 HarvardOxford4 0.234243 0.4657222 C
25 1102 Lh__F1_head 0.387666 0.4657222 C
26 1102 Lh__F2_body 0.387666 0.4657222 C
27 1102 Lh__F3_tail 0.387666 0.1212333 C
28 1102 Rh__F1_head 0.387666 0.4657222 C
29 1102 Rh__F2body 0.234243 0.1212333 C
30 1102 Rh__F3tail 0.234243 0.1212333 C
I want it in the wide format so that for each id there is only one row. So something like:
id roi.A mean.A sd.A roi.A mean.A. sd.A ... roi.C
1 1102 Harvard.Oxford1 0.2342 0.12123 HarvardOxford2 0.1111 0.12123 ... Harvard
Any ideas?