R c.Date() 引发警告 Calling 'structure(NULL, *)' is deprecated [英] R c.Date() raises warning Calling 'structure(NULL, *)' is deprecated
问题描述
我注意到调用 c.Date() 来初始化一个空的日期向量会引发警告.我使用的是 R 版本 3.4.0.
警告信息是:
<块引用>警告信息:在结构中(c(unlist(lapply(list(...), unclass))),class = "Date") :不推荐调用结构(NULL,*)",因为NULL 不能有属性.考虑'结构(列表(),*)'相反.
有人解释一下吗?如何在没有此警告的情况下初始化空的 DATE 向量?
可重现的代码:
vect = c.Date()d = as.Date("31/12/2018", format = "%d/%m/%Y")for(i 在 1:10){vect = c(vect, d)d = d+1}打印(矢量)
结果是
<块引用>[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 在 1:10){vect = c(vect, d)d = d+1}打印(矢量)
<块引用>
[1] 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905
这是不可取的.
r2evans 回答了我的问题.Sys.Date()[0]
诀窍.
我在这里发帖是为了将其标记为已解决,以供将来的读者使用.
I noticed that calling c.Date() to initialize an empty date vector raises a Warning. I am on R version 3.4.0.
The warning message is :
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.
Do anyone has an explantion? How to initialize an empty DATE vector without having this warning?
A reproducible code :
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)
Result is
[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"
If I don't use c.Date() but c() instead.
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
which is undesirable.
r2evans answerd my question.
Sys.Date()[0]
does the trick.
I post here to mark it as resolved for future readers.
这篇关于R c.Date() 引发警告 Calling 'structure(NULL, *)' is deprecated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!