I have a data frame with a column for date that has a character mode.
我有一个数据框,其中包含一个具有字符模式的日期列。
$ Date : chr "2014-01-11 17:50:53.000"
However, I want to remove the ".000" that trails most of the four mills values in my variable. I'm not sure if all of them are ".000" as there are over four million observations but I want to remove the period and everything to it's right so that the dates look as follows.
但是,我想删除跟踪变量中四个铣刀值大部分的“.000”。我不确定它们是否都是“.000”,因为有超过四百万的观察结果,但是我想删除期间和一切正确,以便日期如下所示。
$ Date : chr "2014-01-11 17:50:53"
I can do the following to extract just the date, but I need to do something to extract just the time.
我可以执行以下操作来提取日期,但我需要做一些事情来提取时间。
> date = c("2014-01-11 17:50:53.000")
> as.Date(date)
[1] "2014-01-11"
How can I do this in R?
我怎么能在R中这样做?
1 个解决方案
#1
1
You can extract just the element you want with strftime
:
您可以使用strftime仅提取所需的元素:
chrDate <- "2014-01-11 17:50:53.000"
strftime(chrDate, "%H:%M:%S")
#[1] "17:50:53"
#1
1
You can extract just the element you want with strftime
:
您可以使用strftime仅提取所需的元素:
chrDate <- "2014-01-11 17:50:53.000"
strftime(chrDate, "%H:%M:%S")
#[1] "17:50:53"