R c.Date() 引发警告 Calling 'structure(NULL, *)' is deprecated

R c.Date() raises warning Calling 'structure(NULL, *)' is deprecated

我注意到调用 c.Date() 来初始化空日期向量会引发警告。我使用的是 R 版本 3.4.0。

警告消息是:

Warning message: In structure(c(unlist(lapply(list(...), unclass))), class = "Date") : Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes. Consider 'structure(list(), *)' instead.

有人解释一下吗?如何在没有此警告的情况下初始化空 DATE 向量?

可重现的代码:

vect = c.Date()
d = as.Date("31/12/2018", format = "%d/%m/%Y")
for(i in 1:10){
    vect = c(vect, d)
    d = d+1
}
print(vect)

结果是

[1] "2016-03-31" "2016-04-01" "2016-04-02" "2016-04-03" [5] "2016-04-04" "2016-04-05" "2016-04-06" "2016-04-07" [9] "2016-04-08" "2016-04-09"

如果我不使用 c.Date() 而是使用 c()。

vect = c()

d = as.Date("31/12/2018", format = "%d/%m/%Y")
for(i in 1:10){
  vect = c(vect, d)
  d = d+1
}

print(vect)

[1] 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905

这是不可取的。

r2 evans 回答了我的问题。 Sys.Date()[0] 做的伎俩。

我post在这里将其标记为已解决以供将来的读者使用。