Performing count in column given a condition specified in a different column?
显示 更早的评论
I have formed a table after doing some data cleaning. It contains two columns, one which has a score of 1 or 0 and one which specifies which question type was being answered (i.e. 'MAY' or 'DG'). I want to add up the total for 'MAY' and 'DG' separately, but have run into trouble.
Was planning to use an equivalency (as here https://uk.mathworks.com/matlabcentral/answers/questions/new/?s_tid=gn_mlc_ans_ask) but when converting to matrix using cell2mat I receive this error
```Error using cell2mat (line 42)
Subscripting a table using linear indexing (one subscript) or
multidimensional indexing (three or more subscripts) is not supported. Use
a row subscript and a variable subscript.```
Any support would be much appreciated
1 个评论
Matt J
2018-7-7
Your link doesn't point to any examples/documentation.
采纳的回答
更多回答(1 个)
Matt J
2018-7-7
varfun(@sum,yourTable,'GroupingVariables',1)
3 个评论
Frederick Herbert
2018-7-7
Frederick Herbert
2018-7-9
You can do,
T=varfun(@(c) {c}, yourTable,'GroupingVariables',1);
类别
在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!