Asign subjects to groups and get a group average
1 view (last 30 days)
Show older comments
Hi all,
I have a table containing 3 Variables - Subject ID (N = 1026) , Group ID (Total of 457 groups) and IQ score (one for each subject).
What I am trying to do is to
a) get a list telling me the subjects IDs belonging to each group
b) get an average IQ score for each group
Doesn't seem to be that hard of a problem but I am struggling...
Any help would be appreciated!!
Thanks,
Johanna
0 Comments
Accepted Answer
Chunru
on 10 May 2022
% 3 Variables - Subject ID (N = 1026) , Group ID (Total of 457 groups) and IQ score (one for each subject).
N = 1026;
id = randperm(N)';
gr = randi([1 457], [N, 1]);
iq = randi([80 200], [N, 1]);
data = table(id, gr, iq);
head(data)
% a) get a list telling me the subjects IDs belonging to each group
gr0 = data.gr(1); % group to be identified
a = data(data.gr == gr0, :);
head(a)
% b) get an average IQ score for each group
groupsummary(data, 'gr', 'mean', 'iq')
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!