datetime - rounding times to the nearest hour in R -
this question has answer here:
i have data in format
time <- c("16:53", "10:57", "11:58")
etc
i create new column each of these times rounded nearest hour. cannot seem posix command work me.
as.character(format(data2$time, "%h:%m"))
error in format.default(structure(as.character(x), names = names(x), dim = dim(x), : invalid 'trim' argument
let alone use round command. can advise?
## example times x <- c("16:53", "10:57", "11:58") ## posix*t objects need both date , time specified ## here, particular date doesn't matter -- there one. tt <- strptime(paste("2001-01-01", x), format="%y-%m-%d %h:%m") ## use round.date round, format format format(round(tt, units="hours"), format="%h:%m") # [1] "17:00" "11:00" "12:00"
Comments
Post a Comment