add a row of summary statistics in a table
14 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Voss
2022-6-18
t = table({'new york';'chicago'},[10;5],[17;18],'VariableNames',{' ','visitor','temperature'})
t(end+1,:) = {'' sum(t{:,'visitor'}) mean(t{:,'temperature'})}
0 个评论
更多回答(1 个)
the cyclist
2022-6-18
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!