Summing rows by month in R

后端 未结 4 562
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 05:55

So I have a data frame that has a date column, an hour column and a series of other numerical columns. Each row in the data frame is 1 hour of 1 day for an entire year.

4条回答
  •  猫巷女王i
    2020-12-06 06:24

    Another base R solution

    # to sum by date
    rowsum(dat[-1], dat$Date)
    #           Hour Melbourne Southern Flagstaff
    #2009-05-01   21         0      496       715
    
    # or by month and year
    rowsum(dat[-1], format(dat$Date, "%b-%y") )
    #       Hour Melbourne Southern Flagstaff
    #May-09   21         0      496       715
    

提交回复
热议问题