【问题标题】:Why Does Using ymd_hms Function Result in "All formats failed to parse. No formats found"?为什么使用 ymd_hms 函数会导致“所有格式解析失败。未找到格式”?
【发布时间】:2019-04-17 18:08:49
【问题描述】:

尝试运行 mdy_hms。获取以下内容:

> mdy_hms(gary)
[1] NA NA NA
Warning message:
All formats failed to parse. No formats found. 

输入文件如下:

encounter_id,disease_id,date
1,2,"04-17-2019 13:00:01"

我做错了什么?

谢谢,加里

【问题讨论】:

  • 您只需要传入要转换的列。您不能将整个 data.frame 传递给 mdy_hms

标签: r lubridate


【解决方案1】:

它应该工作。 您需要在列而不是数据框上使用

lubridate::mdy_hms("04-17-2019 13:00:01")
"2019-04-17 13:00:01 UTC"

【讨论】:

  • 我的文件有 2000 万行。
  • 试试gary$date <- lubridate::mdy_hms(gary$date)
  • 谢谢,桑尼!如您所知,我是 R 新手。现在这很有意义 - 我很容易在向量、数据帧等之间混淆。
猜你喜欢
  • 2020-04-11
  • 2021-06-03
  • 2015-07-10
  • 2021-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
相关资源
最近更新 更多