Asign subjects to groups and get a group average
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Chunru
le 10 Mai 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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!