MATLAB: How to user grpstats function in this case

grpstats

I have a table like (the real table is more complicated)
date month person spending
1/1/2020 January-2020 John 30
1/1/2020 January-2020 Mike 15
1/2/2020 January-2020 John 20
1/3/2020 January-2020 Kate 30
then I want to create a summary table such as
person 'count of John's spending data' 'sum of John's spending' 'average of John's spending per observation'
January-2020
February-2020
Please advise.

Best Answer

>> grpstats(thuey,{'person','month'},{'mean','@sum'},'DataVars',{'spending'})
ans =
3×5 table
person month GroupCount mean_spending Fun2_spending
______ ________ __________ _____________ _____________
John_Jan-2020 John Jan-2020 2 25 50
Kate_Jan-2020 Kate Jan-2020 1 30 30
Mike_Jan-2020 Mike Jan-2020 1 15 15
>>