Groupby Date and Categorical Column on Tables

4 ビュー (過去 30 日間)
Furqan Hashim
Furqan Hashim 2020 年 8 月 28 日
コメント済み: Furqan Hashim 2020 年 8 月 29 日
Suppose that I have 5 columns in my table as Stock, Date, Open, High, Low, Close. Stock is a string column and Date is in Date format. Suppose that same stock can repeat on same day.
How can I count of unique stocks on each Day? That would be table with number of unique stock counts against each date.
Given that each stock can have mutiple observation on same day how can I group by both Date and Stock to get average Open price for each stock on each day.
  23 件のコメント
Furqan Hashim
Furqan Hashim 2020 年 8 月 29 日
Adam Thanks a lot for the help! Much appreciated.


回答 (1 件)

Mohammad Sami
Mohammad Sami 2020 年 8 月 29 日
Perhaps you can try the alternative below.
if true
[G,tabout] = findgroups(data(:,{'Stock','Date'}));
tabout.avgOpen = splitapply(@mean,data.Open,G);
  4 件のコメント
Adam Danz
Adam Danz 2020 年 8 月 29 日
The only difference between your and my versions is the update #9. You could easily update your version for free by pressing the little bell icon in the upper right of the main window. I can't promise that will affect this problem but it's a good idea to get the updates anyway.






Community Treasure Hunt

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

Start Hunting!

Translated by