How to to calculate each decile average based on group?
2 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I have a table with variables 'Date', 'Volumn'. Now I want to first group the variable by 'Date', then under each group, I want to calculate the average of first decile of 'Volumn'. Finally I want to generage a new table associates 'Date' and the calculated 'Average First Decile Volumn'. Is there any easy way to do this?
Thanks a lot.
0 个评论
回答(1 个)
Jalaj Gambhir
2019-7-30
编辑:Jalaj Gambhir
2019-7-30
Hi,
In a table, you can first group rows using unique date values in the Date column, then compute your required statistics using accumarray. You can refer to the example below:
dates = T.Date;
[uniqueDates,ua,uc] = unique(dates);
mean_T = accumarray(uc,T.Volumn,[],@mean);
new_table = table(uniqueDates,mean_T);
You can replace @mean with your function to compute average first decile. Refer prctile for the same.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!