[R] How to sum and group data by DATE in data frame
R. Michael Weylandt
michael.weylandt at gmail.com
Wed May 16 16:27:39 CEST 2012
Fascinating... dput() has never given me anything that looks like
that.... I would have expected something much more like
z <- structure(c(123.53, 123.78, 124.24, 124.2, 124.07, 123.91, 123.44,
123.0616, 123.06, 123.13, 123.745, 123.96, 123.99, 123.99, 124.3,
124.38, 124.67, 125.19, 124.9, 125.27, 125.5, 125.58, 125.91,
125.8, 125.83, 126.215, 126.25, 126.25, 124.901, 124.43, 124.4654,
124.46, 124.68, 124.86, 124.73, 125.22, 125.48, 125.5601, 125.4091,
125.15, 125.43, 125.481, 125.91, 125.29, 124.79, 124.77, 124.7,
124.37, 124.56, 124.86, 125.3, 125.59, 125.95, 125.73, 126.27,
126.26, 127.33, 126.37, 126.46, 126, 126.06, 126.2662, 126.23,
126.4499, 127.12, 127.48, 127.49, 127.69, 127.88, 127.88, 124.51,
124.42, 124.92, 125.18, 125.23, 124.81, 125.07, 124.61, 123.8869,
123.24, 123.3329, 123.6, 123.19, 123.161), index = structure(c(1320258600,
1320260400, 1320262200, 1320264000, 1320265800, 1320267600, 1320269400,
1320271200, 1320273000, 1320274800, 1320276600, 1320278400, 1320280200,
1320282000, 1320345000, 1320346800, 1320348600, 1320350400, 1320352200,
1320354000, 1320355800, 1320357600, 1320359400, 1320361200, 1320363000,
1320364800, 1320366600, 1320368400, 1320431400, 1320433200, 1320435000,
1320436800, 1320438600, 1320440400, 1320442200, 1320444000, 1320445800,
1320447600, 1320449400, 1320451200, 1320453000, 1320454800, 1320697800,
1320699600, 1320701400, 1320703200, 1320705000, 1320706800, 1320708600,
1320710400, 1320712200, 1320714000, 1320715800, 1320717600, 1320719400,
1320721200, 1320784200, 1320786000, 1320787800, 1320789600, 1320791400,
1320793200, 1320795000, 1320796800, 1320798600, 1320800400, 1320802200,
1320804000, 1320805800, 1320807600, 1320870600, 1320872400, 1320874200,
1320876000, 1320877800, 1320879600, 1320881400, 1320883200, 1320885000,
1320886800, 1320888600, 1320890400, 1320892200, 1320894000), class =
c("POSIXct",
"POSIXt"), tzone = ""), class = "zoo")
which is about 100x more convenient....
With that,
aggregate(z, as.Date(time(z)), sum)
and
aggregate(z, format(time(z), "%m %d"), sum)
give different results (at least in my time zone) so try the latter
(it seems to be what you were probably looking for)
If that doesn't nail it down, I'll need you to answer the questions I
asked in my previous email.
Best,
Michael
On Wed, May 16, 2012 at 6:14 AM, Cren <oscar.soppelsa at bancaakros.it> wrote:
>
> Michael Weylandt wrote
>>
>> Can you provide a reproducible example?
>>
> Of course, Michael.
>
> Consider the following time series:
>
>
> 11/2/2011 14:30 123.53
> 11/2/2011 15:00 123.78
> 11/2/2011 15:30 124.24
> 11/2/2011 16:00 124.2
> 11/2/2011 16:30 124.07
> 11/2/2011 17:00 123.91
> 11/2/2011 17:30 123.44
> 11/2/2011 18:00 123.0616
> 11/2/2011 18:30 123.06
> 11/2/2011 19:00 123.13
> 11/2/2011 19:30 123.745
> 11/2/2011 20:00 123.96
> 11/2/2011 20:30 123.99
> 11/2/2011 21:00 123.99
> 11/3/2011 14:30 124.3
> 11/3/2011 15:00 124.38
> 11/3/2011 15:30 124.67
> 11/3/2011 16:00 125.19
> 11/3/2011 16:30 124.9
> 11/3/2011 17:00 125.27
> 11/3/2011 17:30 125.5
> 11/3/2011 18:00 125.58
> 11/3/2011 18:30 125.91
> 11/3/2011 19:00 125.8
> 11/3/2011 19:30 125.83
> 11/3/2011 20:00 126.215
> 11/3/2011 20:30 126.25
> 11/3/2011 21:00 126.25
> 11/4/2011 14:30 124.901
> 11/4/2011 15:00 124.43
> 11/4/2011 15:30 124.4654
> 11/4/2011 16:00 124.46
> 11/4/2011 16:30 124.68
> 11/4/2011 17:00 124.86
> 11/4/2011 17:30 124.73
> 11/4/2011 18:00 125.22
> 11/4/2011 18:30 125.48
> 11/4/2011 19:00 125.5601
> 11/4/2011 19:30 125.4091
> 11/4/2011 20:00 125.15
> 11/4/2011 20:30 125.43
> 11/4/2011 21:00 125.481
> 11/7/2011 15:30 125.91
> 11/7/2011 16:00 125.29
> 11/7/2011 16:30 124.79
> 11/7/2011 17:00 124.77
> 11/7/2011 17:30 124.7
> 11/7/2011 18:00 124.37
> 11/7/2011 18:30 124.56
> 11/7/2011 19:00 124.86
> 11/7/2011 19:30 125.3
> 11/7/2011 20:00 125.59
> 11/7/2011 20:30 125.95
> 11/7/2011 21:00 125.73
> 11/7/2011 21:30 126.27
> 11/7/2011 22:00 126.26
> 11/8/2011 15:30 127.33
> 11/8/2011 16:00 126.37
> 11/8/2011 16:30 126.46
> 11/8/2011 17:00 126
> 11/8/2011 17:30 126.06
> 11/8/2011 18:00 126.2662
> 11/8/2011 18:30 126.23
> 11/8/2011 19:00 126.4499
> 11/8/2011 19:30 127.12
> 11/8/2011 20:00 127.48
> 11/8/2011 20:30 127.49
> 11/8/2011 21:00 127.69
> 11/8/2011 21:30 127.88
> 11/8/2011 22:00 127.88
> 11/9/2011 15:30 124.51
> 11/9/2011 16:00 124.42
> 11/9/2011 16:30 124.92
> 11/9/2011 17:00 125.18
> 11/9/2011 17:30 125.23
> 11/9/2011 18:00 124.81
> 11/9/2011 18:30 125.07
> 11/9/2011 19:00 124.61
> 11/9/2011 19:30 123.8869
> 11/9/2011 20:00 123.24
> 11/9/2011 20:30 123.3329
> 11/9/2011 21:00 123.6
> 11/9/2011 21:30 123.19
> 11/9/2011 22:00 123.161
>
> The rownames are datas plus hour, the data column is the time series' value.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-sum-and-group-data-by-DATE-in-data-frame-tp903708p4630228.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list