Re: [R] Compiling a contingency table of counts by case

From: Jacques VESLOT <jacques.veslot_at_good.ibl.fr>
Date: Fri 22 Sep 2006 - 16:18:15 GMT

what's different from:
 > with(dat, tapply(x, list(name,case), sum))

       1 2 3
Joe 1 1 NA
John NA 1 NA
Karl NA NA 0
Mike 1 0 1

and how to deal with this table ?



Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr


hadley wickham a écrit :
>>I have asked a similar question before but this time
>>the problem is somewhat more involved. I have the
>>following data:
>>
>>case;name;x
>>1;Joe;1
>>1;Mike;1
>>1;Zoe;1
>>2;Joe;1
>>2;Mike;0
>>2;Zoe;1
>>2;John;1
>>3;Mike;1
>>3;Zoe;0
>>3;Karl;0
>>
>>I would like to count the number of "case"
>>in which any two "name"
>>
>>a. both have "x=1",
>>b. the first has "x=0" - the second has "x=1",
>>c. the first has "x=1" - the second has "x=0",
>>d. both have "x=0",
>
>
> One way is to use the reshape package:
>
> dat <- read.delim("clipboard", sep=";")
> dat <- rename(dat, c(x=value))
> cast(dat, name ~ case)
>
> (which doesn't give you exactly what you want, but I think might be
> more illuminating)
>
> Hadley
>
> ______________________________________________
> 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.
>



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 Sat Sep 23 02:23:01 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 Fri 22 Sep 2006 - 17:30:19 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.