data.table:最后一次失败的日期向量

时间:2014-11-10 14:28:49

标签: r data.table

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

发生了什么事?

1 个答案:

答案 0 :(得分:0)

根据上述评论进行评论,is.vector(as.Date(f))FALSE,因此它不是矢量。您需要首先使用xts加载library(xts),然后加载data.table并且您的代码应该正常工作(从那时起data.table将能够在{{1}上调用xts::last对象)。