How to use groupsummary to group by hour-of-year

22 ビュー (過去 30 日間)
Dino Bellugi
Dino Bellugi 2023 年 6 月 30 日
回答済み: Peter Perkins 2023 年 7 月 17 日
The "groupsummary" function offers a convenient way to group variables in a table and apply functions such as computing the mean.
For example, if I want to compute the day-of-year mean of a variable named "foo" in a table "myTable" containing daily data with timestamp "date", I would use the command:
myDoyTable = groupsummary(myTable, "date","dayofyear","mean","foo");
This is great for daily data, but I am stumped in the case of hourly data.
Suppose I want to do a similar thing, but now myTable contains hourly data and date has an hourly timestamp.
Ideally I would want to use a command such as:
myDoyTable = groupsummary(myTable, "date","hourofyear","mean","foo");
Unfortunately, there is no "hourofyear" option (though there is hour of day, minute of hour, and many more).
Can anyone suggest a workaround?
Thanks,
-Dino

回答 (2 件)

the cyclist
the cyclist 2023 年 6 月 30 日
The groupbin option "hour" doesn't do what you want?
(If not, can you upload a sample of input and output data indicating what you want? I'm having a difficult time understanding.)
  4 件のコメント
Dino Bellugi
Dino Bellugi 2023 年 7 月 2 日
Thanks, that's clever! I will give it a try and let you know..
Dino Bellugi
Dino Bellugi 2023 年 7 月 2 日
Here is the data, BTW, apologies for not uploading it earlier. I'm interested in the hour of year mean for column AP, namely "Fch4_f_1_1_1". I had to chop off the data file after a few years, due to size limitations. Feel free to take it for a spin, cyclist! Thanks again, -d.

サインインしてコメントする。


Peter Perkins
Peter Perkins 2023 年 7 月 17 日
Is this really "hour of year", a value that runs from 0 to 8784? In the same way that day of year is just
dt = datetime(2023,7,17,14,15,0)
dt = datetime
17-Jul-2023 14:15:00
doy = between(dateshift(dt,"start","year"),dt,"days") % or maybe - caldays(1)
doy = calendarDuration
197d
hour of year is just
hoy = between(dateshift(dt,"start","year"),dt,"time")
hoy = calendarDuration
4742h 15m 0s
hoy = floor(time(hoy),"hours"); hoy.Format = 'h'
hoy = duration
4742 hr
If you add an HoY grouping variable to your table, groupsummary can group by that.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by