Your original dates are not in an unambiguous format, so it is better to explicitly define the date format, I would say you should take a more individualized approach for both described cases:
library(dplyr)
library(lubridate)
library(stringr)
sample_data <- data.frame(
stringsAsFactors = FALSE,
column = c("44686","44662","16/05/22",
"44686","44648","44564","44571","44571","16/05/22",
"30/05/22")
)
sample_data %>%
mutate(column = if_else(
str_detect(column, "/"),
dmy(column),
as.Date(as.numeric(column), origin = "1899-12-30")
))
#> Warning: 7 failed to parse.
#> Warning in as.Date(as.numeric(column), origin = "1899-12-30"): NAs introducidos
#> por coerción
#> column
#> 1 2022-05-05
#> 2 2022-04-11
#> 3 2022-05-16
#> 4 2022-05-05
#> 5 2022-03-28
#> 6 2022-01-03
#> 7 2022-01-10
#> 8 2022-01-10
#> 9 2022-05-16
#> 10 2022-05-30
Created on 2022-06-06 by the reprex package (v2.0.1)