[R] Combining tables

jim holtman jholtman at gmail.com
Mon Sep 15 03:27:21 CEST 2008


try this:

> c(tx,ty)
1 2 3 3 4
3 2 1 4 1
> z <- c(tx,ty)
> tapply(z, names(z), sum)
1 2 3 4
3 2 5 1
>


On Sun, Sep 14, 2008 at 9:04 PM, Andre Nathan <andre at digirati.com.br> wrote:
> Hello
>
> Say I have the following data, and it's distribution given by table():
>
>  > x <- c(1, 1, 1, 2, 2, 3)
>  > tx <- table(x)
>  > tx
>  x
>  1 2 3
>  3 2 1
>
> Now say I have new data,
>
>  > y <- c(3, 3, 3, 3, 4)
>  > ty <- table(y)
>  > ty
>  y
>  3 4
>  4 1
>
> Is there a way to "combine" tx and ty in such a way to give me the
> distribution below?
>
>  1 2 3 4
>  3 2 5 1
>
> Essentially what I'm looking for is something equivalent to
> table(c(x,y)), but x and y are too large and I'd like to avoid the
> concatenation.
>
> Thanks in advance,
> Andre
>
> ______________________________________________
> R-help at 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list