Asign subjects to groups and get a group average
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Johanna Popp
el 10 de Mayo de 2022
Comentada: Johanna Popp
el 10 de Mayo de 2022
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 comentarios
Respuesta aceptada
Chunru
el 10 de Mayo de 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')
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!