• Register
0 votes
2k 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

Please log in or register to answer this question.

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 77 views
0 votes
2 answers 2.3K views
2.3K 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
1 vote
1 answer 18 views
18 views
I am new to this. I just want to know how to do that?
asked Nov 3, 2020 TeamScript 9.5k points
0 votes
1 answer 25 views
25 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 49 views
1 vote
1 answer 1.4K views
1.4K 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, 2020 morrisBson 3.2k points
0 votes
1 answer 1.8K views
1.8K views
Problem : I have been facing below error message and traceback: Error in FUN(X[[i]], ...) : only defined on the data frame with all numeric variables 5 stop("only defined on the data frame with all numeric variables") 4 FUN(X[[i]], ...) 3 lapply(args, ... .numeric(data[good,]) But now I get the different error message back as below : "Error: (list) object cannot be coerced to type 'double'"
asked Dec 16, 2019 alecxe 7.5k points
0 votes
2 answers 145 views
145 views
Problem : I am stuck because of following weired error error in sort.list(y) : 'x' must be atomic for 'sort.list' have you called 'sort' on a list?
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 94 views
0 votes
1 answer 71 views