[R] CROSSTABULATION
Charles C. Berry
cberry at tajo.ucsd.edu
Thu Nov 13 20:21:47 CET 2008
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
More information about the R-help
mailing list