Transform data from long to wide format
13 views (last 30 days)
Show older comments
Hi community,
My data is currently in long format (data_long.csv) and I am trying to convert it to wide format (data_wide.csv).
I have 15 participants and 16 variables to do this for. Any tips would be great!
Thank you,
Danielle
0 Comments
Answers (1)
Star Strider
on 12 Jul 2022
Use unstack, preferably the same unstack call with the same MATLAB version that produced the ‘data_wide’ file.
Experiment with it, since I cannot get the same result.
L1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1062580/data_long.csv')
W1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1062585/data_wide.csv')
L1toW2 = unstack(L1,{'Var1','Time'},'Con')
.
2 Comments
Star Strider
on 13 Jul 2022
It depends on wthe result you want. I used two grouping variables and it seemed to work (R2022a). The result provided seems to have changed over the last few versions. You will likely have to experiment with it.
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!