I have string like 1/1/-2150
. How to make Date
format from that in R
lubridate
back:
library(lubridate)
dmy("1/1/-2150")
[1] "2150-01-01"
as.Date("1/1/-2150",format="%d/%m/%Y")
[1] NA
Now 1/1/-2150
have class character.
I need same value but with class Date
Thanks
UPDATE
Something like that, but using lubridate
if it possible
minus=as.numeric(dmy("1/1/-2150"))
x<-as.numeric(ymd("0000-1-1"))
dt=as.Date(x*2-minus,origin="1970-01-01")+days(1)
str(dt)
Date[1:1], format: "-2150-01-01"
Unfortunately there aren't any really large R packages tackling this issue (maybe no one has asked). The gregorian package should however, be able to tackle your BCE needs.
gregorian::as_gregorian("-2150-1-1") [1] "Tuesday January 1, 2151 BCE"
Late to the party but here is a possible solution here. Find how far 2150-01-01 is from 0000-01-01 and then make it a negative number and pass it to as.Date()
with the origin '0000-01-01'
y <- as.numeric(as.Date("2150-01-01"))+ as.numeric(as.Date("1970-01-01") - as.Date("0000-01-01"))
y
#785272
x <- as.Date(-y, "0000-01-01")
x
#"-2151-12-31"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With