与yearmon的聚合函数

时间:2017-08-19 08:07:08

标签: r aggregate zoo

我正在尝试在R

中运行以下代码
attach(Bilbao)
work1 <- table(Date,District)
work2 <- zoo(x=work1, order.by=as.Date(rownames(work1)))
work3 <- aggregate(x = work2, by = as.yearmon, FUN=sum)) #Error
coredata(work3) <- 100*coredata(work3) / rowSums(work3)

我在定义work3时遇到错误

work3 <- aggregate(x = work2, by = as.Date(rownames(work2), FUN=sum))
  

aggregate.data.frame(as.data.frame(x),...)中的错误:       参数必须具有相同的长度   我试着检查work1和work2的输出,看起来如下所示

work1
            District
Date         Abando - Albia Basurto - Zorroza Begoña - Santutxu
  2004-11-17              0                 0                 1
  2004-11-19              0                 1                 0
  2004-11-24              0                 0                 0


Work2
           District
Date         Abando - Albia Basurto - Zorroza Begoña - Santutxu
  2004-11-17              0                 0                 1
  2004-11-19              0                 1                 0

我无法确定为什么在work3中发生此错误。请帮忙

0 个答案:

没有答案