Is there a way to make as.Date() and strptime() process strings with
negative years? It appears that Date objects can contain negative years and
you can convert them to strings, but you can't convert them back to Date
objects.


x <- as.Date(c("0001-01-24", "0500-01-24"))
as.character(x)
# "0001-01-24" "0500-02-02"
as.Date(as.character(x))
# "0001-01-24" "0500-01-24"

# Minus 391 days gives negative year
as.character(x - 391)
# "-001-12-30" "0498-12-29"

# Can't convert this string back to Date
as.Date(as.character(x - 391))
# Error during wrapup: character string is not in a standard unambiguous
format


# as.Date.character uses strptime, so we can try using strptime directly
strptime(as.character(x), "%Y-%m-%d")
# "0001-01-24" "0500-01-24"

strptime(as.character(x - 391), "%Y-%m-%d")
# NA           "0498-12-29"


Thanks,
-Winston

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to