varfun for a cell array?

1 ビュー (過去 30 日間)
Angelavtc 2020 年 3 月 31 日
コメント済み: Angelavtc 2020 年 4 月 1 日
Is there a way to apply varfun(@mean,A,'GroupingVariable','VariableX')to all the elements that are contained into a cell array? If yes, how?
Thanks a lot!
  5 件のコメント
Angelavtc 2020 年 4 月 1 日
Yes, OP has a 300x1 cell array :)



Adam Danz
Adam Danz 2020 年 3 月 31 日
編集済み: Adam Danz 2020 年 4 月 1 日
I didn't quite get the last part of your description but this should get you started. If you have trouble completing your goal, please elaborate.
The key is using cellfun to evaluate a function for each element of a cell array.
% C is the [n x 1] cell array containing tables with the same headers.
% Create function to be executed on each table T
tableFcn = @(T)varfun(@mean,T,'GroupingVariable','Price');
% Compute the grouped mean for each variable
A= cellfun(tableFcn, C, 'UniformOutput', false)
% Get all values where groupcount==2
selectedGroupCount = cellfun(@(T){T(T.GroupCount == 2, :)}, A);
% Convert the cell array of tables into a final table
Afinal = vertcat(selectedGroupCount{:});
  7 件のコメント
Angelavtc 2020 年 4 月 1 日
@Adam Danz thank you so much! this is exactly what I need it... I will give it a try :)


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by