FW: [R] Crosstabulation

Murray Jorgensen maj at waikato.ac.nz
Mon Sep 25 01:38:44 CEST 2000


At 09:16 PM 24-09-00 +0200, =?us-ascii?Q?Jacob_Anhoj?= wrote:
>how about this: tapply(vector,list(factor1,factor2),function)?

Thank you, Jacob.  I've tried it out on this example on housing
satisfaction in
Copenhagen taken from Annette Dobson's book on GLMs. It works fine!

count <- scan()
65 130 67 54 76 48 100 111 62 34 141 130 47 116 105 100 191 104

s <- c("Lo", "Med", "Hi")
satisfaction <- factor( rep(c(s,s), rep(3,6)),
                 levels = c("Lo","Med","Hi"))
contact <- factor( rep(c("Low","High"), rep(9,2)),
                 levels = c("Low","High"))
r <- c("Tower", "Flat", "House")
residence <- factor(rep(r,6))


tapply(count,list(satisfaction,contact,residence),sum)




>-----Original Message-----
>From: owner-r-help at stat.math.ethz.ch
>[mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Murray Jorgensen
>Sent: 24. september 2000 02:46
>To: R-help
>Subject: [R] Crosstabulation
>
>
>I can't seem to find a function in R similar to Splus crosstabs() for
>creating a multi-way table from factors and a count vector.
>
>
>Murray Jorgensen

Dr Murray Jorgensen       http://www.stats.waikato.ac.nz/Staff/maj.html 
Department of Statistics, University of Waikato, Hamilton, New Zealand 
*Applications Editor, Australian and New Zealand Journal of Statistics* 
maj at waikato.ac.nz Phone +64-7 838 4773 home phone 856 6705 Fax 838 4155

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list