ddply,按日期排列

ddply, arrange by date

ddply 可以按月而不是按字母顺序排列数据框吗? 这是一个数据示例:

df <- data.frame(Count=c(674, 1, 165, 5, 6458, 1809, 141, 35611, 34, 9043, 283, 512, 337, 78761, 131),date=c("12-09", "07-23", "06-02", "06-13", "07-27", "10-16", "06-13", "07-10", "05-22", "11-26", "10-21", "04-03", "04-30", "12-02", "06-14"), Factor=rep(c('a','b','c'),5))
df$date <- as.Date(df$date,format="%m-%d")

ddply 按字母顺序排列数据

ddply(df,.(format(date,"%b")),summarize,Sum=sum(Count))

我应该如何按时间顺序获取东西?

我建议使用 lubridate:

这样的包
library(lubridate)
ddply(df, .(month = month(date, label = T, abbr = T)), summarize, Sum = sum(Count))
#   month   Sum
# 1   Apr   849
# 2   May    34
# 3   Jun   442
# 4   Jul 42070
# 5   Oct  2092
# 6   Nov  9043
# 7   Dec 79435