无法将字符串转换为R中的日期 [英] Cannot convert string to date in R
问题描述
我需要您的帮助,以找出以下问题 -
我试图将日期列从字符串转换为实际日期格式。我尝试使用as.Date
但是,它显示一条错误消息:
charToDate(x)中的错误:
字符串不是以标准的无歧义格式
我在csv文件中的日期列是这样的:
p>
03/17/2003
05/31/2003
09/06/2003
10/18/2003
07/15/2003
09/19/2003
问题是某些日期是字符串,有些是实际日期格式。我试图从excel格式化 - 没有工作
尝试复制并粘贴到记事本,然后再次导入 - 也不工作。
您需要了解R中的帮助系统。简单看一下 help(as.Date)
可能告诉你关于格式参数:
R& dt <-c(03/17/2003,05/31/2003,09/06/2003)
R> as.Date(dt,%m /%d /%Y)
[1]2003-03-172003-05-312003-09-06
R& ;
I need your help to figure out the following problem-
I am trying to convert a date column from string to actual date format. I have tried using as.Date
However, it is showing an error message: Error in charToDate(x) : character string is not in a standard unambiguous format
the date column I have in csv file is like this:
Date
03/17/2003
05/31/2003
09/06/2003
10/18/2003
07/15/2003
09/19/2003
The problem is some of the dates are in string and some are in actual date format. I have tried to format it from excel - didn't work Tried to copy and paste it to notepad and then import it again - didn't work either.
You need to learn about the help system in R. One brief look at help(as.Date)
may have told you about the format argument:
R> dt <- c("03/17/2003", "05/31/2003", "09/06/2003")
R> as.Date(dt, "%m/%d/%Y")
[1] "2003-03-17" "2003-05-31" "2003-09-06"
R>
这篇关于无法将字符串转换为R中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!