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

 채택된 답변

Peter Perkins
Peter Perkins 2017년 11월 16일

0 개 추천

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

UQFG
UQFG 2017년 11월 16일
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);
Peter Perkins
Peter Perkins 2017년 11월 16일
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'.
UQFG
UQFG 2017년 11월 16일
편집: UQFG 2017년 11월 16일
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에 대해 자세히 알아보기

질문:

2017년 11월 13일

편집:

2017년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by