【发布时间】:2021-01-31 11:55:52
【问题描述】:
我有一个数据框,其中有一列包含 mm/yy 格式的日期。但是,该列是字符类型,我想将其更改为日期以进行绘图。
示例代码如下:
x <- c("01/20","02/20","03/20")
as.Date(x,format = "%m/%y")
我收到以下错误:
Error in charToDate(x) :
character string is not in a standard unambiguous format
如果可能,我想使用 as.Date。
【问题讨论】:
-
“01/20”代表 2020 年 1 月,“02/20”代表 2020 年 2 月,等等?
-
试试
as.Date(paste0('01/',x),format = "%d/%m/%y")