add a row of summary statistics in a table
Mostra commenti meno recenti
Suppose I have a table in Matlab:
Then I want to add a summary statistics (sum for the first col and average for the second col)
Then how shall I proceed?
Risposta accettata
Più risposte (1)
Here is one way:
% The table
T = table([10;5],[17;18],'VariableNames',{'visitor','temperature'},'RowNames',{'New York','Chicago'});
% Numeric variables for the mean
vars = {'visitor','temperature'};
% Calculate the mean
varsMean = mean(T{:,vars});
% Append mean to table, and change the RowNames property of that row
T{end+1,vars} = varsMean;
T.Properties.RowNames{end} = 'mean';
% Display
T
2 Commenti
alpedhuez
il 18 Giu 2022
the cyclist
il 18 Giu 2022
Oh, sorry. I misread. Looks like you got an effectively equivalent answer.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!