我有数据价值
dput(a)
"1/3/2019 15:59"
我需要将时间缩短到下一个小时。我需要这个日期是"1/3/2019 16:00"
?
我怎样才能做到这一点?
我们可以使用lubridate
dmy_hm
转换为datetime对象,然后使用ceiling_date
将其转换为下一个小时。
library(lubridate)
ceiling_date(dmy_hm("1/3/2019 15:59"), "hour")
#[1] "2019-03-01 16:00:00 UTC"
使用round.POSIXt
。没有使用包裹。
x <- as.POSIXct("1/3/2019 15:59", format = "%m/%d/%Y %H:%M")
round(x + 3600/2 - !(as.numeric(x) %% 3600), "hours")
## [1] "2019-01-03 16:00:00 EST"