【发布时间】:2018-11-21 10:19:03
【问题描述】:
我的数据框如下图:
str(Rainfall_Complete)
'data.frame': 8221 obs. of 18 variables:
$ Date : Date, format: "1985-04-29" "1985-04-30" "1985-05-01" ...
$ Month : Ord.factor w/ 12 levels "Jan"<"Feb"<"Mar"<..:
$ Season : Factor w/ 4 levels "Monsoon","PostMonsoon",..:.
$ Year : chr "1985" "1985" "1985" "1985" ...
$ Stn A : num 0 8.8 0 15 26.2 0 2.5 0 0 0 ...
$ Stn B : num 0 0 26 11 13.8 20 0.26 0 0 0 ...
$ Stn C : num 0.1 0 0 0 13.5 27 16 5 0 0 …
我想将上述每日时间序列转换为每月时间序列 我希望我的数据看起来像这样
Year Month StnA StnB StnC……..
1985 Jan 150 100 120
1985 Feb 120 98 58
….
2010 Jan 200 100 87
2010 Feb 140 145 120
我尝试了以下方法,但它仅适用于单变量系列
library(dplyr)
Monthly_rainfall <- Rainfall_Complete %>% group_by(Year,Month)%>% summarise()
任何帮助将不胜感激
【问题讨论】:
-
您需要先将年月转换为正确的日期格式,稍后使用您的代码即可进行转换
-
如果您想在多个列上使用
summarise,请尝试summarise_at。根据您的分组,您将能够同时获得多个列的sum。 -
也许
padr::thicken()会有所帮助。 -
请看一下如何制作reproducible example,以便更容易提供帮助