last
不适用于日期向量:
library(data.table)
f <- c("2014-11-10","2014-11-11")
last(f)
[1] "2014-11-11"
last(as.Date(f))
Error in last(as.Date(f)) :
data.table::last is trying to defer to xts::last because either x is not a vector, list, data.frame or data.table, or parameters such as 'n' or 'keep' have been provided as well. But xts hasn't been loaded.
?last
承诺的“有用”消息说该参数不是矢量(它是!)并且需要一个我不知道的包xts
。
发生了什么事?
答案 0 :(得分:0)
根据上述评论进行评论,is.vector(as.Date(f))
为FALSE
,因此它不是矢量。您需要首先使用xts
加载library(xts)
,然后加载data.table
并且您的代码应该正常工作(从那时起data.table将能够在{{1}上调用xts::last
对象)。