Aggregate Daily Data to Month/Year intervals

I’d do it with lubridate and plyr, rounding dates down to the nearest month to make them easier to plot:

library(lubridate)
df <- data.frame(
  date = today() + days(1:300),
  x = runif(300)
)
df$my <- floor_date(df$date, "month")

library(plyr)
ddply(df, "my", summarise, x = mean(x))

Leave a Comment