필터 지우기
필터 지우기

How to to calculate each decile average based on group?

조회 수: 3 (최근 30일)
Elbert Liu
Elbert Liu 2019년 7월 25일
편집: Jalaj Gambhir 2019년 7월 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에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by