Determine if 24 hour datetime is within interval

烂漫一生 提交于 2019-12-02 00:37:17

Just use a format and comparsion via >=:

format(datetimes,"%H") >= 16
#[1] FALSE  TRUE FALSE  TRUE

Assuming you have already converted via as.POSIXct() as shown in your question.

Even though format returns a character string, the comparison is safe to do with a numeric as all the single digit values are padded like "08"

The lubridate package makes this really easy. See https://cran.r-project.org/web/packages/lubridate/vignettes/lubridate.html for more info.

library(lubridate)
hour(as.POSIXct(datetimes))>16
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!