Clear Filters
Clear Filters

MEAN OF A VARIABLE WITH RESPECT TO OTHER VARIABLES

39 views (last 30 days)
SAPTORSHEE KANTO
SAPTORSHEE KANTO on 21 Aug 2024 at 12:05
Commented: SAPTORSHEE KANTO on 22 Aug 2024 at 5:24
I would like to find mean of the variable a25 other variable a6a7 and by year .
input int(year a6a7) long a25
2017 121 12000
2017 121 30000
2017 121 13000
2017 121 14000
2017 121 15000
2017 121 15000
2017 121 15000
2017 121 20000
2017 121 15000
2017 121 8000
2017 121 10000
2017 121 14000
2017 121 35000
2017 121 6000
2017 121 2000
2017 121 10000
2017 17 15000
2017 17 15000
2017 17 12000
2017 17 15000
2017 17 15000
2017 17 8000
2017 17 7000
2017 17 5000
2017 121 10000
2017 121 10000
2017 121 6000
2017 121 8000
2017 121 8000
2017 121 12000
2017 121 10000
2017 121 10000
2017 121 16000
2017 121 8000
2017 121 12000
2017 121 15000
2017 121 15000
2017 121 15000
2017 121 8000
2017 121 10000
2017 121 10000
2017 121 8000
2017 121 6000
2017 121 6000
2017 121 6000
2017 121 10000
2017 121 10000
2017 121 10000
2017 121 7000
2017 121 8000
2017 121 10000
2017 121 10000
2017 121 15000
2017 121 5000
2017 121 10000
2017 121 10000
2017 17 25000
2017 17 8000
2017 17 8000
2017 17 10000
2017 17 7000
2017 17 6000
2017 17 3500
2017 17 8000
2017 17 20000
2017 17 16000
2017 17 16000
2017 17 14000
2017 17 25000
2017 17 15000
2017 17 16000
2017 17 16000
2017 121 12000
2017 121 15000
2017 121 12000
2017 121 12000
2017 121 13000
2017 121 12000
2017 121 14000
2017 121 8000
2017 120 5000
2017 120 5000
2017 120 4000
2017 120 5000
2017 120 3000
2017 120 4000
2017 120 4000
2017 120 4000
2017 119 6000
2017 119 6000
2017 119 4000
2017 119 5000
2017 119 5000
2017 119 7000
2017 119 7000
2017 119 6000
2017 16 20000
2017 16 15000
2017 16 20000
2017 16 15000
end
[/CODE]

Answers (2)

Voss
Voss on 21 Aug 2024 at 13:08

Ronit
Ronit on 22 Aug 2024 at 4:33
Hello Saptorshee,
To calculate the mean of the variable a25 grouped by the variables a6a7 and year in MATLAB, you can use the groupsummary function. First, you'll need to create a table from your data, then use this function to compute the mean.
% Load and extract the data matrix from the .mat file
loadedData = load("datafile.mat");
data = loadedData.data;
% Convert the data to a table
T = array2table(data, 'VariableNames', {'Year', 'A6A7', 'A25'});
% Use groupsummary to calculate the mean of A25 grouped by Year and A6A7
result = groupsummary(T, {'Year', 'A6A7'}, 'mean', 'A25');
disp(result);
Year A6A7 GroupCount mean_A25 ____ ____ __________ ________ 2017 16 4 17500 2017 17 24 12729 2017 119 8 5750 2017 120 8 4250 2017 121 56 11536
Here is the documentation link of groupsummary function for more details: https://www.mathworks.com/help/matlab/ref/double.groupsummary.html
I hope it helps you query!

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!