HI, May be this helps: t2 <- table(c(10,11,12,13)) t1 <-table(c(1,1,2,4,5)) t <- c(t1,t2) tapply(t,sort(as.numeric(names(t))),sum)
A.K. On Monday, December 9, 2013 7:01 PM, Ross Boylan <r...@biostat.ucsf.edu> wrote: Can anyone recommend a good way to add tables? Ideally I would like t1 <- table(x1) t2 <- table(x2) t1+t2 It t1 and t2 have the same levels this works fine, but I need something that will work even if they differ, e.g., > t1 1 2 4 5 2 1 1 1 > t2 <- table(c(10, 11, 12, 13)) > t1+t2 # apparently does simple vector addition 1 2 4 5 3 2 2 2 whereas I want 1 2 4 5 10 11 12 13 2 1 1 1 1 1 1 1 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.