[R] Tabulation

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 10 17:36:52 CEST 2009


Here are a couple of possibilities both based on first converting the
data frame to long form:

> xtabs(~ind + values, stack(DF))
    values
ind  1 2 3
  x1 3 1 1
  x2 2 3 0
  x3 3 1 1
> t(table(stack(DF)))
    values
ind  1 2 3
  x1 3 1 1
  x2 2 3 0
  x3 3 1 1


On Sat, Oct 10, 2009 at 10:43 AM, Ashta <sewashm at gmail.com> wrote:
> Hi all,
>
> I have a data set
> x1  x2 x3
>  1   2   1
>  1   2   3
>  2   1   2
>  1   2   1
>  3   1   1
>
>  I want to tabulate in the following way.
>        1   2   3
>  x1    3   2   1
>  x2    2   3   0
>  x3    3   1   1
>
> It is just like frequency distribution
>
>
> Any help is highly appreciated
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list