Average of different rows depending on the last column value
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2016년 3월 9일
If you have the Statistics and Machine Learning Toolbox, you can use grpstats().
means = grpstats(t, 'Customer_desc');
댓글 수: 2
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!