Re: [R] merge counts from table()

2012-08-14 Thread Francois Pepin
Thanks for all the replies. The merge solution is what I was groping toward but the factor solution is much cleaner since I do know in advance what the possible categories are. François On Aug 14, 2012, at 2:39 , PIKAL Petr wrote: > Hi > > If your x and y are factors it seems to be easy, jus

Re: [R] merge counts from table()

2012-08-14 Thread PIKAL Petr
Hi If your x and y are factors it seems to be easy, just add all levels in both. x.f<-factor(x, levels=1:5) y.f<-factor(y, levels=1:5) table(x.f)+table(y.f) x.f 1 2 3 4 5 1 2 2 2 1 If you just have output from table(x) without possibility to add levels you can go with merge > mm <- merge(a

Re: [R] merge counts from table()

2012-08-13 Thread Rui Barradas
Hello, My earlier solution has a problem. If you have billions of counts over ~150 categories, it will recreate the full vectors every time you add a new category, thus causing potential memory issues. Another, much more complicated, way but using only the tables info is as follows. twotabl

Re: [R] merge counts from table()

2012-08-13 Thread David L Carlson
If you know all of the categories in advance, you can convert x and y to factors and then sum the tables: > x<-1:4 > y<-2:5 > x <- factor(x , levels=1:5) # list all possible categories > y <- factor(y , levels=1:5) > table(x) x 1 2 3 4 5 1 1 1 1 0 > table(y) y 1 2 3 4 5 0 1 1 1 1 > table(c(x,

Re: [R] merge counts from table()

2012-08-13 Thread Rui Barradas
Hello, This one will do it. x <- 1:4 y <- 2:5 t1 <- table(x) t2 <- table(y) (xy <- c(rep(names(t1), t1), rep(names(t2), t2))) table(xy) Hope this helps, Rui Barradas Em 13-08-2012 19:25, Francois Pepin escreveu: Hi everyone, Is there an easy way to combine the counts from table()? Let's