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
e- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Francois Pepin > Sent: Monday, August 13, 2012 1:26 PM > To: r-help@r-project.org > Subject: [R] merge counts from table() > > Hi everyone, > > Is there an easy way to combine

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

[R] merge counts from table()

2012-08-13 Thread Francois Pepin
Hi everyone, Is there an easy way to combine the counts from table()? Let's say that I have: x<-1:4 y<-2:5 I want to replicate: table(c(x,y)) using only table(x) and table(y) as input. The reason is that it's cumbersome to carry all the values around when all I care about are the counts. The