1

I want to group data by date-time / POSIXlt.

I have a data frame which has date-time variable. So I have converted into POSIXlt:

         datetime                value            POSIXlt
1 2015-06-21 21:40:56.934875000    36       2015-06-21 21:40
2 2015-06-21 21:40:57.963022000    35       2015-06-21 21:40
3 2015-06-21 21:40:58.394573000    30       2015-06-21 21:40
4 2015-06-21 21:40:59.349857000    31       2015-06-21 21:40
5 2015-06-21 21:50:56.963022000    11       2015-06-21 21:50
6 2015-06-21 21:50:58.127052000    33       2015-06-21 21:50

And I want output something like this:

    time            sum(value)
2015-06-21 21:40        132
2015-06-21 21:50        44
Frank
  • 66,179
  • 8
  • 96
  • 180
Manoj G
  • 71
  • 5
  • 2
    What is the format of your data.frame? What is the desired output? What do you mean by grouping? –  Jul 16 '15 at 06:09
  • @Pascal: Sorry for the unclear question. Now I added update... – Manoj G Jul 16 '15 at 06:24
  • possible duplicate of [R aggregate data.frame with date column](http://stackoverflow.com/questions/24788450/r-aggregate-data-frame-with-date-column) –  Jul 16 '15 at 06:29
  • 2
    `POSIXlt` doesn't play nice with `aggregate` usually - try: `aggregate(dat["value"],list(time=as.POSIXct(trunc(as.POSIXlt(dat$datetime), units="mins"))),FUN=sum)` – thelatemail Jul 16 '15 at 06:33
  • @thelatemail Oops, didn't saw your comment – akrun Jul 16 '15 at 06:42
  • 1
    @Pascal: I'm was able to aggregate by date. But that doesn't solve my problem. So asked this question... – Manoj G Jul 16 '15 at 06:51
  • @thelatemail: Its working! Thank you. Please add the answer.. – Manoj G Jul 16 '15 at 06:52
  • You can post the answer yourself, giving credit to @thelatemail . – Frank Mar 11 '16 at 17:44

0 Answers0