【发布时间】:2020-05-12 04:28:23
【问题描述】:
我有一个 csv 文件,其中第一列(名为“月”)具有月份数据格式 “Jan\n1990”、“Feb\n1990”等等。 当我使用 read.csv 函数(使用 stringsAsFactors = FALSE)读取 R 中的文件时,它将“月”列读取为“chr”。我想把它转换成日期格式。我试过了
month_1 <- as.Date(f4$month)
但它给出了错误
Error in charToDate(x) :
character string is not in a standard unambiguous format
如何将第一列转换为日期格式的列?
【问题讨论】:
-
日期需要几天...所以你必须提供它和当前变量。使用
paste(..., collapse="...")并从?strftime中计算出所需的格式。 -
是的,这绝对是您可以在 Python 中完成的事情。请参阅
datetime模块。