Is there something similar as splitapply that works on a data table instead just on one value?

4 visualizzazioni (ultimi 30 giorni)
I created a subset of my input data that has more then 400 data sets and called it tex. The Data in each dataset is 13269x3 table, see picture to the right.
I would like to build the maximum for each row of P and QP for all groups of K and L
[perKL,KL,LK] = findgroups(tex.K, tex.L); % The findgroups does its job perferct.
maxByKL = splitapply(@max,tex.Data{:,1}, perKL); % here is the point of question,
Splitapply doesn't work since it expects the same number of rows for the data variable.
Is there already any existing function for that?

Risposta accettata

Matt J
Matt J il 14 Feb 2022
Modificato: Matt J il 14 Feb 2022
Tex=varfun(@(x){table2array(x)},tex,'InputVariables','Data');
out = varfun(@(z)max(cell2mat(z)), Tex,'InputVariables','Data','GroupingVariables',{'K','L'})
  7 Commenti
Matt J
Matt J il 15 Feb 2022
Modificato: Matt J il 15 Feb 2022
I think this is what you mean,
Tex=rowfun(@(x){table2array(x)},tex,'InputVar','Data','OutputVar','Data','Extract',1);
Tex=[tex(:,1:2),Tex];
out = varfun(@(z){max(cat(3,z{:}),[],3)}, Tex,'InputVariables','Data','GroupingVariables',{'K','L'});
out(:,3)=[];
out.Properties.VariableNames{3}='maxByKL'

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by