My excel data is written in POSIXct format (see below)
final_sample <- data.frame(
PN_number = c( "PN101", "PN102", "PN103", "PN104", "PN105"),
Maturity_date_2018 = c(1518048000, 1516665600, 1518134400, 1518048000, 1520812800),
Maturity_date_2019 = c("NULL", 1516665600, "NULL", 1518048000, "NULL"),
Maturity_date_2020 = c(1518048000, "NULL", "NULL", "NULL", 1520812800)
)
And I want to convert these into dates.
I tried to use the following codes, however, the results are not accurate, I even try to convert this manually in excel using this formula: DATE(1970,1,1) + (cell/86400) to check if the results are the same.
final_sample_all <- final_sample %>%
mutate(across(starts_with("Maturity_date_"), ~ifelse(!is.na(as.numeric(.)),
as.Date(as.POSIXct(as.numeric(.), origin = "1970-01-01", tz = "UTC"), origin = "1970-01-01"),
"NULL")))