Changing data from long form to short form
8 次查看(过去 30 天)
显示 更早的评论
Hi all,
I wondered if someone might be able to help - with what might seem like a super easy tast.
I have data in longform i.e. (a simple example of what I have below, example 1), but I ideally need it in short form i.e. one row per participant see example 2.
Example 1.
Participant_ID Trial RT
1 1 342
1 2 346
1 3 534
2 1 242
2 2 131
2 3 531
Example 2.
Participant_ID 1_RT 2_RT 3_RT
1 342 346 534
2 242 131 531
Is there a simple way I can do this?
Thank you in advance,
Rachel
0 个评论
回答(3 个)
Steven Lord
2019-9-12
编辑:Steven Lord
2019-9-12
Participant_ID = [1; 1; 1; 2; 2; 2];
Trial = [1; 2; 3; 1; 2; 3];
RT = [342; 346; 534; 242; 131; 531];
t = table(Participant_ID, Trial, RT);
unstackedTable = unstack(t,'RT','Trial');
0 个评论
Rik
2019-9-11
You can use the participant ID and trial ID as the indices and either use accumarray or sub2ind to fill the matrix with the values. I would suggest sub2ind if you can guarantee that every combination of trial and participant is unique.
0 个评论
Walter Roberson
2019-9-11
Under the assumption that all of the information for each participant is gathered together and that there are exactly the same number of data points per participant, then:
[Particpant_ID(1:number_of_trials:end), reshape(RT, number_of_trials).']
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!