Average of different rows depending on the last column value
1 view (last 30 days)
Show older comments
I have a 1000x5 matrix suppose wherein, first column is customer_id and last column is customer_desc which will be 1,2,3, or 4 for all the customers and columns 2 till 4 are data of which I need to take the mean depending on the value of customer_desc. Ex the output needs to be like this: -
Customer_desc Average col2 Average Col3 Average col4
----------------------------------------------------------------
1 0.235742555 0.325659159 0.283776929
2 0.511820228 0.311237444 0.394172541
3 0.254775313 0.352126843 0.306672852
4 0.365448276 0.345090639 0.354142646
I can do this using a for loop but I wanted to vectorize the calculation. Also I need to calculate the average of a customer_desc/ sum(average(other customer_desc)) as well. Any suggestions/ideas would be helpful.
0 Comments
Answers (1)
Image Analyst
on 9 Mar 2016
If you have the Statistics and Machine Learning Toolbox, you can use grpstats().
means = grpstats(t, 'Customer_desc');
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!