I want to count new elements that were not in previous years. In the example
Sample data:
var1 <- list('2003' = 1:3, '2004' = c(4:3), '2005' = c(6,4,1), '2006' = 1:4 )
I would like to get a conclusion
newcount <- list('2003' = 0, '2004' = 1, '2005' = 1, '2006' = 0)
Bad code:
newcount <- mapply(setdiff, var1, seq_along(var1), function(i) {if (i > 1) {Reduce(union, var1[i-1], accumulate=T)}}, length)
r lapply
dmvianna
source share