【发布时间】:2020-05-22 05:35:23
【问题描述】:
我尝试使用tsibble 将缺少值的日期列转换为年-周格式。这样做会返回解析失败或数值结果。
最终输出应如下所示:2020 W1, 2020 W6。
有没有办法使用tsibble 包解决这个问题?奇怪的是,这个包的 yearmonth 函数也适用于 NA 和空值。
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".
【问题讨论】: