Skip to content
Prev 85621 / 398506 Next

15-min mean values

Here's another approach which can be easily implemented in SQL.
1. Start with the dates as character vectors,
   dt <- as.character(Sys.time())
2. Extract the minutes and round them to 0,15,30,45:
   minutes <- floor(as.numeric(substr(dt,15,16))/15)*15
   final.mins <- as.character(minutes)
   final.mins[final.mins == "0"] <- "00"
3. Get the dates you need for aggregating:
   final.dt <- paste(substr(dt,1,14),final.mins,":00",sep="")
(If you had wanted to use 10 minutes, it would have been enough to
transform MM:SS to M0:00.)
4. Use aggregate(), SQL GROUP BY etc
5. Finally, convert final.dt from character to datettime.