フィルターのクリア

Aggregating data into a panel structure

2 ビュー (過去 30 日間)
James Stewart
James Stewart 2020 年 9 月 15 日
回答済み: Monisha Nalluru 2020 年 9 月 18 日
I have a data set ~30,000 obs. I want to aggregate(sum) one vector over three others so it is in a panel data structure.
I have the variables: Zone(4 level factor), Suburbs(20level factor), Year(10 level factor), and #ofHouses.
I want the sum of the #ofHouses for each Zone, for each Suburb and for each year.
i.e. the panel data structure needs to be indexed by the i,j,t (i=zone,j=suburb,t=time)
Is there a matlab function for this? I found accumarray but can't figure out how it works for this data.

回答 (1 件)

Monisha Nalluru
Monisha Nalluru 2020 年 9 月 18 日
findgroup function is used to split the data based on the group and return groups numbers
splitapply function is used to apply the required function of the group and return the result
As an example from patients data first I am dividing the group based on Gender,Smoker,Age and at the end I was calculating the mean weight for each group
load patients.mat
GT=table(Gender,Smoker,Age);
[G,results] = findgroups(GT);
meanweight=splitapply(@mean,Weight,G);
results.meanWeight=meanweight;
results
You can use similar like above example!

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by