splitapply table for zscore

I have a table in the format:
Group Score
A 3
B 7
C 18
A 10
How do I combine the splitapply function for table variables with zscore , such that it calculates zscore(Score) according to Group rather than the whole table?
I have tried:
[G,results] = findgroups(Table.Group);
ZS = splitapply(@zscore,Table.Score,G);
results.ZS = ZS

 采纳的回答

splitapply is more for computing scalar summaries. Try using varfun, with a grouping variable, returning a table. Something like
t2 = varfun(@zscore,t,'GroupingVariable','Group')

3 个评论

Thanks, that does seem to be appropriate... however, when I try to apply it, I get the following errors:
Error using getGroupingVarOrTime (line 13) Unrecognized variable name 'Table.Group'.
Error in tabular/varfun (line 130) groupVars = getGroupingVarOrTime(groupVars, a);
I'm guessing you have a table named 'Table' (which is probably not a great idea), and a variable in it named 'Group'. The error is telling you that you do not have a variable named 'Table.Group'.
I actually don't... I just used those names as generic examples!
I just realised that you don't need the "Table." in front of the Group name... so the code that works is:
ZS=varfun(@zscore,Table,'GroupingVariables','Group')
Whereas what I had before was:
ZS=varfun(@zscore,Table,'GroupingVariables','Table.Group')

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by