How to to calculate each decile average based on group?

1 vue (au cours des 30 derniers jours)
Elbert Liu
Elbert Liu le 25 Juil 2019
Modifié(e) : Jalaj Gambhir le 30 Juil 2019
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.

Réponses (1)

Jalaj Gambhir
Jalaj Gambhir le 30 Juil 2019
Modifié(e) : Jalaj Gambhir le 30 Juil 2019
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.

Community Treasure Hunt

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

Start Hunting!

Translated by