I try to convert a date column with missing values into year-week format with tsibble
. Doing this returns either in parsing failures or numeric outcomes.
The final output shall look like this: 2020 W1, 2020 W6.
Is there a way to solve this using the tsibble
package? Strangly, the yearmonth
function of this package works also with NA and empty values.
library(tsibble)
library(lubridate)
x <- c("2020-01-01", "", "2020-02-06")
yearweek(x)
# Output: fails
ifelse(x == "", "", yearweek(ymd(x)))
# Output: "18260" "" "18295"
# Desired Output: "2020 W1", "", "2020 W6".