[R] Combining tables

Andre Nathan andre at digirati.com.br
Mon Sep 15 03:04:04 CEST 2008


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



More information about the R-help mailing list