【问题标题】:Trying to format dates column from chr to Date but returning NA [duplicate]尝试将日期列从 chr 格式化为 Date 但返回 NA [重复]
【发布时间】:2022-02-14 06:47:19
【问题描述】:

我已经导入了 xlsx 文件,并且有一列日期作为字符:

Jan 08
Feb 08
Mar 08
Apr 08

等等……

我想将此列转换为日期。我尝试了一些我在其他线程上看到的建议,但我无法让它不返回 NA

这是最新的尝试:

dates <- format(as.Date(MonthlyUKFigures$Date,format="%b-%y"),format="%b-%y")

【问题讨论】:

标签: r date


【解决方案1】:

您可以简单地使用lubridate 包:

my("Jan 08")
[1] "2008-01-01"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 2018-01-07
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2019-07-18
    • 2023-01-03
    相关资源
    最近更新 更多