Re: [R] CROSSTABULATION

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Thu, 13 Nov 2008 11:21:47 -0800

On Thu, 13 Nov 2008, Sohail wrote:

> I want to form a 3x3 crosstabulation for the signs of two vectors (i.e.
> Negative, Zero, Positive). The problem is that I am simulating the data so
> for some iterations one of the categories is absent. Thus the resulting
> table shrinks to 3x2. I want it to be 3x3 with zero column corresponding to
> the missing category. Moreover, I have tried but failed to give the
> dimension names.

See

         ?factor

Something like this might be what you want:

> table(sign(rnorm(5)),sign(rnorm(5)))

      -1 1
   -1 1 1
   1 1 2
> sign.factor <- function(x) factor( sign(x), -1:1 )
> table(sign.factor(rnorm(5)),sign.factor(rnorm(5)))

      -1 0 1
   -1 0 0 4
   0 0 0 0
   1 0 0 1
>

HTH, Chuck

> --
> Sohail Chand
>
> PhD Scholar
> C3b Pope Building
> School of Mathematical Sciences
> University of Nottingham
> Nottingham
> NG7 2RD
> UK
>
> Lecturer (On Study Leave)
> Institute of Statistics
> University of the Punjab
> Quaid-i-Azam Campus, Lahore (Pakistan)
>
> [[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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

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. Received on Thu 13 Nov 2008 - 19:26:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Nov 2008 - 19:31: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.

list of date sections of archive