필터 지우기
필터 지우기

New to Matlab. I need help with group (?), double counting, and so on. Thank you!

조회 수: 1 (최근 30일)
JB
JB 2020년 6월 4일
댓글: JB 2020년 6월 4일
New to Matlab, I need your help.
Suppose my data is this:
schoolid classid classsize enrollment
1001 1 10 22
1001 2 12 22
1005 1 14 29
1005 2 15 29
1018 1 8 22
1018 2 4 22
1018 3 10 22
.
.
.
And I want to find:
a. number of schools.
I found this one by
grps = findgroups(schoolid);
n = max(grps);
b. the average number of classes in a school.
I know how to solve by hand, but you know, my data is big,,, help me with codes please.
c. Provide the histogram of enrollment, and report its mean, median, max and min.
I know codes to find histogram, mean, and so on,
but you see the enrollemnt column is a double counting, I need to figure this out frist.
Please help me... Matlab geniuses... Thank you!

채택된 답변

Image Analyst
Image Analyst 2020년 6월 4일
For a, and alternate way is
numberOfSchools = length(unique(schoolid))
A for loop way for b and c is
us = unique(schoolid)
numRows = length(schoolid)
for k = 1 : length(us)
thisSchoolsRows = schoolid == us(k); % Only rows with this particular school
numClasses(k) = length(thisSchoolsRows) % Assumes each classid's are unique and show up in only one row for a particular school.
end
aveClassesOverAllSchools = numClasses(k) / numberOfSchools
You can use the same approach to compute your other statistics. You can also use grpstats() or splitapply() like Rik mentioned.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by