如何将两个变量的每小时数据转换为每日平均值?
我正在努力观察PM 10数据,每天平均3年。我已经处理了空气质量数据,但是,我的温度和风速数据小时为止。如何计算每日平均水平并结合这两个数据?
例如:
日期 | 温度 | wind_speed |
---|---|---|
1/01/2018 1:00 | 18.8 | 1.9 |
1/01/2018 2:00 2:00 | 18.7 | 1.5 |
1/01/2018 3:00 3:00 | 18.6 | 1.6 |
1/01/01/2018 4:00 | 18.5 1.0 1.0 | |
1/01/2018 5:00 | 18.1 | 1.2 |
...一直到1/1/2021 00:00(26304 OBS)。
我尝试过
StartDateTime = dmy_hm("-01-01-2018 01:00")
EndDateTime <- dmy_hm("01-01-2021 00:00")
DF <- data.frame(DateTime = c(seq.POSIXt(StartDateTime, EndDateTime, by = "hour"),
seq.POSIXt(StartDateTime, EndDateTime, by = "hour")),
check.rows = TRUE, fix.empty.names = TRUE,
)
head(DF)
- 它将DF更改为一个变量和52608 OBS。我在这个阶段超级迷路。
我的PM10数据是一个时间序列[1:1096] - 原子向量。关于如何在温度和风速上将每小时数据更改为每日平均水平的任何建议,以便我可以将其与PM10数据相结合?
数据:dput(head(sample_data_1))
I am working on observing PM 10 data on a daily average for 3 years. I have already worked on my air quality data however, my temperature and wind speed data are hourly. How can I calculate the daily average and combine both of these data?
Eg:
date | temperature | Wind_Speed |
---|---|---|
1/01/2018 1:00 | 18.8 | 1.9 |
1/01/2018 2:00 | 18.7 | 1.5 |
1/01/2018 3:00 | 18.6 | 1.6 |
1/01/2018 4:00 | 18.5 1.0 | |
1/01/2018 5:00 | 18.1 | 1.2 |
... all the way until 1/1/2021 00:00 (26304 obs).
I tried
StartDateTime = dmy_hm("-01-01-2018 01:00")
EndDateTime <- dmy_hm("01-01-2021 00:00")
DF <- data.frame(DateTime = c(seq.POSIXt(StartDateTime, EndDateTime, by = "hour"),
seq.POSIXt(StartDateTime, EndDateTime, by = "hour")),
check.rows = TRUE, fix.empty.names = TRUE,
)
head(DF)
- It changed the DF into one variable and 52608 obs. I am super lost at this stage.
My pm10 data has is a time series [1:1096]- atomic vector. Any suggestions on how I can change the hourly data into daily average for both temperature and wind speed so I can combine it with the pm10 data?
data: dput(head(sample_data_1))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的数据看起来像
df2
(并且您使用lubridate
),那么您可以在
group_by <
group_by中创建一个新的
date
变量/代码>和使用
汇总
:在2022-06-10创建的平均值,由(v2.0.1)
I'm assuming your data looks like
DF2
(and you uselubridate
)Then you can create a new
date
variable ingroup_by
andcalculate the average using
summarise
:Created on 2022-06-10 by the reprex package (v2.0.1)