我想计算前几年不存在的新元素。在示例中
样本数据:
var1 <- list('2003' = 1:3, '2004' = c(4:3), '2005' = c(6,4,1), '2006' = 1:4 )
我想得到输出
newcount <- list('2003' = 0, '2004' = 1, '2005' = 1, '2006' = 0)
不成功的代码:
newcount <- mapply(setdiff, var1, seq_along(var1), function(i)
{if (i > 1) {Reduce(union, var1[i-1], accumulate=T)}}, length)