Skip to content
Prev 294752 / 398503 Next

How to sum and group data by DATE in data frame

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: