Can't convert numeric to date in R

Viewed 154

I'm trying to convert some dates that are currently set as numeric to a date class. e.g. 19870101

for example:

> as.Date.numeric(19870101, origin = "1970-01-01")
[1] "56417-06-28"

Why does this not return the correct date which should be "1987-01-01". Does anyone know what I am doing wrong here, is the origin argument wrong?

Any ideas? Thanks!

1 Answers
library(lubridate)
ymd(19870101)

output

[1] "1987-01-01"
Related