R is new for me and i'm working with a (private)dataset.
I have the following problem, i have a lot of time series:
2015-04-27 12:29:48
2015-04-27 12:31:48
2015-04-27 12:34:50
2015-04-27 12:50:43
2015-04-27 12:53:55
2015-04-28 00:00:00
2015-04-28 00:00:10
All the timeseries have a value:
Datetime value
2015-04-27 12:29:48 0.0
2015-04-27 12:31:48 0.0
2015-04-27 12:34:50 1.1
2015-04-27 12:50:43 45.0
2015-04-27 12:53:55 0.0
2015-04-28 00:00:00 1.0
2015-04-28 00:00:10 2.0
I want to skip all the hours and minutes, and sum it all together like this:
Datetime value
2015-04-27 46.1
2015-04-28 3.0
The first thing i did was transform the column datetime:
energy$datetime <- as.POSIXlt(energy$datetime)
I tried several stuff with the summarize function:
df %>% group_by(energy$datetime) %>% summarize (energy$newname(energy$value))
But that isn't working.
I also read competitive stuff on the internet (e.g.: http://r.789695.n4.nabble.com/How-to-sum-and-group-data-by-DATE-in-data-frame-td903708.html) but it doesn't make sense to me (yep, i'm a noob).
Hopefully someone could help me!
you are on the right path - try :
summarise(newVal = sum(energy$value) )
for your summarise call.df<- energy %>% group_by(datetime) %>% summarise(sum =sum(value)) )
Use as.Date() then aggregate().
EDIT
Emma made a good point about column names. You can preserve column names in aggregate by using the following instead.
Using the tidyverse, specifically lubridate and dplyr:
Created on 2018-08-01 by the reprex package (v0.2.0).
using data.table