convert to date and strip time?

◇◆丶佛笑我妖孽 提交于 2019-12-05 13:06:39

This looks like it is working:

as.POSIXct(dates, format = '%a, %d %b %Y %H:%M:%S')
#[1] "2017-11-18 GMT" "2017-11-16 GMT" "2017-11-15 GMT" "2017-11-14 GMT"

We can also use dmy_hms from the lubridate package.

library(lubridate)

dmy_hms(dates, tz = "GMT")
# [1] "2017-11-18 GMT" "2017-11-16 GMT" "2017-11-15 GMT" "2017-11-14 GMT"

Use as.Date like this. It ignores junk at the end so this works. No packages are used.

as.Date(dates, "%a, %d %b %Y")
## [1] "2017-11-18" "2017-11-16" "2017-11-15" "2017-11-14"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!