• Register
0 votes
1.4k views

Problem :

Please have a look at the below date related error :

$ R --vanilla
> as.Date("09 Jan 2019")
Error in charToDate(x) :
character string is not in a standard unambiguous format

But that date is clearly in the correct standard unambiguous format. So why am I facing the above error message?

Worst thing is that, an ambiguous date is apparently accepted and without any warning or error and then read very incorrectly! As shown below:

> as.Date("01/01/2000")
[1] "0001-01-20"
6 5 3
7,540 points

1 Answer

0 votes

Solution :

This is the documented behavior. From the ?as.Date:

Format: The character string. If not specified, then it will try '"%Y-%m-%d"' then '"%Y/%m/%d"' on the very first non-'NA' element, and then it will give an error if neither works.

as.Date("09 Jan 2019") gives the error as the format is not in the one of the two listed above. as.Date("01/01/2000") gives an incorrect answer as the date is not in the one of the two formats listed above.

I always take "standard unambiguous" to mean "ISO-8601". If you are receiving above error, then the solution for that is to specify the format of your date in, using the correct formats described in the ?strptime.

Hope my solution helps in resolving your issue.

9 7 4
38,600 points

Related questions

0 votes
1 answer 12 views
12 views
Problem: I am a beginner in the programming world I badly need to execute the query through Java like shown below: public ResultSet execSumStatment2() throws SQLException{ String query = "Select SUM(A) as NCCSeptember from NCC where Datum >= '01-09-2013 00:00:00' and Datum ... the issue is a datatype of my date in my above query which must be Date and everything which I have tried is not working.
asked Jul 25 Raphael Pacheco 4.9k points
0 votes
2 answers 1.6K views
1.6K views
Problem : Below is my code which is giving me the error. plot(x,y) yx.lm <- lm(y ~ x) lines(x, predict(yx.lm), col="red") Why am I facing following error? Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 14 views
1 vote
1 answer 841 views
841 views
Problem : I am very new to R programming. Currently I am learning R programming. I have below two tables I have asembled them via cbind(). My first Table table_alpha is as below: x1 col1_x1 col2_x1 A "1999 12 01 00:00" " 0.4" " 0" B "1999 12 02 00:00" " - ... = table_num[,1], fill=-9999) Please find below the error: &ldquo;Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns&rdquo;.
asked Mar 28 morrisBson 3.2k points