How to sum and group data by DATE in data frame
Can you provide a reproducible example? use dput() to send your data in a reproducible and user-friendly format. (It might not look user friendly, but trust me, it is) If x is really long, perhaps just dput(head(x, 25)) will suffice. Just a guess as to your problem: I'm not familiar with the timeSequence function -- what package is it from? My guess is that the days it's producing are not properly aligned with the days of your time series object. Can you try it with something closer to my example? Best, Michael
On Tue, May 15, 2012 at 12:42 PM, Cren <oscar.soppelsa at bancaakros.it> wrote:
Thank you for your help, Michael. I used *aggregate(x, by = timeSequence(by = "day"), FUN = sum)* but the results is very different from *sum(x[1:13])*, where 13 is the number of daily observations I've sampled. Michael Weylandt wrote
How are you using aggregate()? It seems to sum for me... z <- zoo(1:50, seq.POSIXt(from = Sys.time(), by = "30 min", length.out = 50)) aggregate(z, as.Date(time(z)), sum) Best, Michael On Tue, May 15, 2012 at 11:52 AM, Cren <oscar.soppelsa@> wrote:
Hello, I have a time series with intraday datas, sampled every 30'; I would need to aggregate them in this way: summing up all datas within a day. I tried to use *aggregate(...)* function to get my goal, but it aggregates in wrong way (I did not understand how so far); what I need is like *sum(...)* function applied to datas within the same day. Thank you :) -- View this message in context: http://r.789695.n4.nabble.com/How-to-sum-and-group-data-by-DATE-in-data-frame-tp903708p4630119.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help@ 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.
______________________________________________ R-help@ 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.
-- View this message in context: http://r.789695.n4.nabble.com/How-to-sum-and-group-data-by-DATE-in-data-frame-tp903708p4630139.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.