How to find the mean for each specified range in a table without writing multiple lines of the same code?

1 Ansicht (letzte 30 Tage)
I have this table imported into Matlab and im trying to find the mean for each province and year, using the numbers in the "VALUE" column.
Example, for all rows that have "2015" in column A and "Quebec" in column B, calculate the mean using the values in column D.
stats1=rmmissing(stats1,'DataVariables',{'VALUE'})
stats1 = sortrows(stats1,'REF_DATE','ascend');
stats1 = sortrows(stats1,'GEO','ascend');
AB2015=mean(stats1{1:5,4})
AB2015 =
9.320
I used this method, and it works but I need to find the mean for each year and province so it seems like it would be very repetitive and long. Im wondering if there is an easier way to do this?

Antworten (2)

Walter Roberson
Walter Roberson am 26 Nov. 2022
Like I told you before, use groupsummary (see also findgroups )

Image Analyst
Image Analyst am 26 Nov. 2022
In addition to groupsummary you might also look at grpstats and splitapply

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by