Can anyone explain why the code below produces NAs in c for b1 but values for b2? I can't see why it depends on the order of vector a, given c in both b1 and b2 has the same type.
a1 = c("a", "2022", "2023")
a2 = c("2022", "a", "2023")
b1 = tibble(a1)
b2 = tibble(a2)
b1 %>%
mutate(c = case_when(
!is.na(as.numeric(a1)) ~ as.Date(paste0(a1,"-01-01"), optional = TRUE),
TRUE ~ as.Date(NA)
))
b2 %>%
mutate(c = case_when(
!is.na(as.numeric(a2)) ~ as.Date(paste0(a2,"-01-01"), optional = TRUE),
TRUE ~ as.Date(NA)
))