[R] Force "square" crosstabulation

From: Manuel Morales <Manuel.A.Morales_at_williams.edu>
Date: Sun 03 Dec 2006 - 01:26:59 GMT


Hello list members,

I'm looking for a way to force the results of a crosstabulation to be square - that is, to include 0 values.

For example:

table(letters[1:4],letters[c(1:3,3)])

yields:

    a b c
  a 1 0 0
  b 0 1 0
  c 0 0 1
  d 0 0 1

I would like to return:

    a b c d
  a 1 0 0 0
  b 0 1 0 0
  c 0 0 1 0
  d 0 0 1 0

Any suggestions?

Thanks!

-- 
Manuel A. Morales
http://mutualism.williams.edu

______________________________________________ R-help@stat.math.ethz.ch 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.

Received on Sun Dec 03 12:32:31 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 03 Dec 2006 - 09:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.