如何将每月数据集转换为具有每月格式95%分位数的每月数据集?

时间:2019-05-14 04:19:55

标签: r time-series summary quantile

我有10年的每日数据集时间序列。我想将其转换为10年的每月数据集,但是每月值将是分位数,而不是该月的平均值。如何使用R执行此操作?

1 个答案:

答案 0 :(得分:0)

您可以使用tsibble package来完成此任务。我正在使用nycflights13 R包中的天气数据,这是一个小时数据集。

library(nycflights13)
library(tsibble)

nycflights13::weather %>% 
  mutate(time_month = yearmonth(time_hour)) %>% 
  group_by(origin, time_month) %>% 
  summarise(temp_q25 = quantile(temp, probs = .25, na.rm=T))

   origin time_month temp_q25
   <chr>       <mth>    <dbl>
 1 EWR      2013 Jan     28.9
 2 EWR      2013 Feb     28.9
 3 EWR      2013 Mär     35.1
 4 EWR      2013 Apr     46.9
 5 EWR      2013 Mai     55.9
 6 EWR      2013 Jun     66.9
 7 EWR      2013 Jul     75.9
 8 EWR      2013 Aug     71.1
 9 EWR      2013 Sep     60.1
10 EWR      2013 Okt     53.1
相关问题