转换为日期并剥离时间? [英] convert to date and strip time?

查看:106
本文介绍了转换为日期并剥离时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些看起来像这样的数据:

I have some data that looks like this:

dates <- structure(c(1L, 2L, 4L, 3L), .Label = c("Sat, 18 Nov 2017 00:00:00 GMT", 
                                             "Thu, 16 Nov 2017 00:00:00 GMT", "Tue, 14 Nov 2017 00:00:00 GMT", 
                                             "Wed, 15 Nov 2017 00:00:00 GMT"), class = "factor")

我想将其转换为日期格式,而不是将其作为因素.此外,我想剥离格林尼治标准时间00:00:00,因为它毫无意义

I would like to convert it to a date format instead of having it as a factor. Additionally, I want to strip the 00:00:00 GMT because it is meaningless

我尝试了lubridate,但是格式出现问题:

I tried lubridate but I'm having troubles with the format:

library(lubridate)
mdy(dates)
Warning message:
All formats failed to parse. No formats found.

推荐答案

这似乎正在起作用:

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"

这篇关于转换为日期并剥离时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆