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.

回答(1 个)

Jalaj Gambhir
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.

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by