. Advertisement .
..3..
. Advertisement .
..4..
I am tired of fixing the problem: error in chartodate(x) : character string is not in a standard unambiguous format in the r; even if I get the reference from another forum, it still returns an error:
$ R --vanilla
> as.Date("01 Jan 2000")
Error in charToDate(x) :
character string is not in a standard unambiguous format
To identity the problem, I will show you the detail here:
> as.Date("01/01/2000")
[1] "0001-01-20"
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
How do I do that? Could you support me in improving this problem?
The cause: This behavior is documented.
?as.Date
:as.Date("01 Jan 2000")
returns an error as the format ofas.Date("01 Jan 2000")
is not one of the ones listed above.as.Date("01/01/2000")
returns an error because the date is not in one of these formats.Solution: I interpret “standard unambiguous” to refer to “ISO-8601” (even if
as.Date
isn’t as strict as ISO-8601, since “%m/%d/%Y” isn’t ISO-8601).This error can be fixed by specifying the date format you received. Use the Details section of
?strptime
to do this. You must ensure that both the order and any separators match the format of your in string. You should also be careful if your data contains day/month names or abbreviations. The conversion will depend upon your locationYes, it is (ie in late 2016), thanks
anytime::anydate
from anytime.For some examples, see the following:
These are unambiguous, and should work as you have already stated. They do, thanks to
anydate()
. Without a format.