转换时间-日期以润滑R中的datetime对象?

时间:2018-08-26 12:55:53

标签: r lubridate

以下是我在数据框中获得的一些日期:

"23:46 13-08-2018" "00:10 14-08-2018" "01:09 14-08-2018" "05:53 14-08-2018" "06:09 14-08-2018" "06:11 14-08-2018" "06:25 14-08-2018"
"06:41 14-08-2018" "07:13 14-08-2018" "07:13 14-08-2018" "07:21 14-08-2018" "08:04 14-08-2018" "08:06 14-08-2018" "08:32 14-08-2018"
"08:33 14-08-2018" "09:08 14-08-2018" "09:25 14-08-2018" "09:41 14-08-2018" "11:18 14-08-2018" "12:02 14-08-2018" "12:23 14-08-2018"

通常来说,格式为hh:mm dd-mm-yyyy。

我正在尝试用lubridate parse_date_time来解析它,但是没有运气:

parse_date_time(df$transaction_time, "ymd HMS"):

[1] NA                        "2000-10-14 08:20:18 UTC" "2001-09-14 08:20:18 UTC" NA                        "2006-09-14 08:20:18 UTC"
   [6] "2006-11-14 08:20:18 UTC" NA                        NA                        NA                        NA                       
  [11] NA                        "2008-04-14 08:20:18 UTC" "2008-06-14 08:20:18 UTC" NA                        NA                       

请告知,我正在尝试使用这些格式,但这给了我NA

parse_date_time(df$transaction_time, "HMS ymd")

1 个答案:

答案 0 :(得分:2)

您只需要匹配日期格式:

parse_date_time("23:46 13-08-2018", "H:M d-m-y")