-1

I have this csv data

Date                       Kilometer
2015-01-01 15:56:00          1
2015-01-01 17:40:00          2
2015-01-02 14:38:00          4
2015-01-02 14:45:00          3

And would like to group date and sum kilometer like that

Date                       Kilometer
2015-01-01                   3
2015-01-02                   7
  • Did you do any google search? This seems like such a basic question. http://stackoverflow.com/questions/7615922/aggregate-r-sum – Gopala Jun 12 '16 at 01:57

2 Answers2

1

This can be done using dplyr and lubridate

library(dplyr)
df %>% group_by(Date = lubridate::date(Date)) %>% summarise(Kilometer=sum(Kilometer)) 


        Date Kilometer
      (date)     (int)
1 2015-01-01         3
2 2015-01-02         7
jalapic
  • 12,858
  • 8
  • 53
  • 80
1

We can use data.table

library(data.table)
library(lubridate)
setDT(df)[, .(Kilometer = sum(Kilometer)) , .(Date=date(Date))]
akrun
  • 789,025
  • 32
  • 460
  • 575