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

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Matt J
Matt J el 14 de Feb. de 2022
Editada: Matt J el 14 de Feb. de 2022
Tex=varfun(@(x){table2array(x)},tex,'InputVariables','Data');
out = varfun(@(z)max(cell2mat(z)), Tex,'InputVariables','Data','GroupingVariables',{'K','L'})
  7 comentarios
Matt J
Matt J el 15 de Feb. de 2022
Editada: Matt J el 15 de Feb. de 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'

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by