Performing count in column given a condition specified in a different column?
Show older comments
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 Comment
Matt J
on 7 Jul 2018
Your link doesn't point to any examples/documentation.
Accepted Answer
More Answers (1)
Matt J
on 7 Jul 2018
varfun(@sum,yourTable,'GroupingVariables',1)
3 Comments
Frederick Herbert
on 7 Jul 2018
Frederick Herbert
on 9 Jul 2018
You can do,
T=varfun(@(c) {c}, yourTable,'GroupingVariables',1);
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!