I am having problems rounding the datetime columns in my dataset. I need to round a dataset to the nearest half an hour so I can use it with another dataset that have been already rounded.
I have tried the following:
library(dplyr)
library(lubridate)
library(tidyr)
# Create a datetime column
df$datetime <- with(df, ymd_hm(paste(year, month, day, hour, minute, sep = "-")))
# Round to nearest 0:30:00
df$rounded_datetime <-as.POSIXlt(round(as.double(df$datetime)/(30*60))*(30*60),origin=(as.POSIXlt('1970-01-01')))
the problem is that I get these values:
Why my datetime and rounded time don’t match?