I have a date/time value (POSIXct) where I want to round the "hour" value to a multiple of three (00:00, 03:00, 6:00, 9:00, 12:00...).
So far I've extracted the hour as an integer, rounded it accordingly and inserted it back into a POSIXct format. Is there a quicker, more elegant way? This is my code so far:
timestamp <- as.POSIXct("2015-10-14 14:00")
timestamp.h <- as.numeric(format(timestamp, "%H")) + as.numeric(format(timestamp, "%M"))/60
timestamp.h.up <- ceiling(timestamp.h/3)*3
timestamp.up <- as.POSIXct(paste(format(timestamp, "%Y-%m-%d")," ",timestamp.h.up,":00", sep=""))