I am trying to apply a customized function to a column of excel imported dates.
I apply the next function:
library(janitor)
fun_excel_date <- function(x){
if(is.numeric(x)){
excel_numeric_to_date(as.numeric(
as.character(x)
), date_system = "modern")}
else {
return(NA)
}
}
do.call(rbind, lapply(some_dummy_dates$date, fun_excel_date))
Console output:
# [,1]
#[1,] 3967
#[2,] 7783
#[3,] 6028
#[4,] 4479
When applied over one element the function works fine, say excel_numeric_to_date(as.numeric(as.character(29536)), date_system = "modern") as it returns "1980-11-11".
However when applied over an entire column the function returns an unexplained numeric output.
The problem persists even changing x argument to x <- as.Date(x, origin="1899-12-30") inside the function.
data
some_dummy_dates <-structure(list(date = c(29536, 33352, 31597, 30048)), class = "data.frame", row.names = c(NA,
-4L))
Am I missing something inside the function? Is there any other approach?