【问题标题】:Parsing an RFC 822 (email) formatted datetime in R?在 R 中解析 RFC 822(电子邮件)格式的日期时间?
【发布时间】:2016-07-02 01:06:24
【问题描述】:

我有一个数据框列,其中包含电子邮件中使用的 RFC 822 日期时间格式的字符串。例如:

Mon, 14 May 2001 16:39:00 -0700 (PDT)

如何将这些解析为 Date 对象列?

我认为它类似于format(x, "%a, %d %b %Y %H:%M:%S %z (%Z)"),但我还没有让它成功运行。我可以使用任何包(例如lubridate)。

【问题讨论】:

  • format 用于从日期时间类到字符串,而不是相反。您需要as.POSIXctstrptime,例如as.POSIXct('Mon, 14 May 2001 16:39:00 -0700 (PDT)', format = "%a, %d %b %Y %H:%M:%S %z")
  • 谢谢,你是对的,我使用了错误的功能。 as.POSIXct 似乎有效。我用这个发布了一个答案。如果您需要功劳或有更好的解决方案,请随意添加您自己的答案。

标签: r date datetime


【解决方案1】:

as.POSIXct 似乎有效。我使用来自dplyrmutate 将此应用于数据框列:

df <- mutate(df, dates = as.POSIXct(dates, format = "%a, %d %b %Y %H:%M:%S %z"))

【讨论】:

    猜你喜欢
    • 2013-09-04
    • 2010-12-23
    • 2010-09-22
    • 2013-06-13
    • 2013-06-15
    • 2011-04-22
    • 1970-01-01
    • 2013-05-22
    • 2014-10-11
    相关资源
    最近更新 更多