[R] ftable and xtabs

From: Amnon Melzer <amnon.melzer_at_eighty20.co.za>
Date: Wed, 12 Mar 2008 15:45:42 +0200


Hoping someone can help me with xtabs and ftable. I'm trying to get a pair of ftables (possibly more) next to each other. For example:  

> dunhill_lights_xtab<-ftable(xtabs(grossedupobs ~ gender+age_group +
dunhill_lights, data = ciggs))

> dunhill_lights_xtab

                 dunhill_lights          No         Yes

gender age_group                                       

Female 16-24                    4013099.665   11182.244

       25-34                    3563054.240   11378.064

       35-49                    4195272.629    5857.494

       50+                      3799539.477    8433.474

Male   16-24                    4173320.528   16692.498

       25-34                    3873070.488   23458.505

       35-49                    4113760.574   17419.423

       50+                            0.000       0.000

 

. this gives me my first table, and then .  

> camel_filters_xtab<-ftable(xtabs(grossedupobs ~ gender+age_group +
camel_filters, data = ciggs))

> camel_filters_xtab

                 camel_filters          No         Yes

gender age_group                                      

Female 16-24                   4017419.038    6862.871

       25-34                   3570648.429    3783.875

       35-49                   4196824.033    4306.090

       50+                     3792671.966   15300.985

Male   16-24                   4152031.616   37981.410

       25-34                   3837536.726   58992.267

       35-49                   4066210.315   64969.682

       50+                           0.000       0.000

 

I'd like to create one table, essentially both these tables stuck together, something like  

> cbind(dunhill_lights_xtab, camel_filters_xtab)

        [,1] [,2] [,3] [,4]

[1,] 4013100 11182.244 4017419 6862.871

[2,] 3563054 11378.064 3570648 3783.875

[3,] 4195273 5857.494 4196824 4306.090

[4,] 3799539 8433.474 3792672 15300.985

[5,] 4173321 16692.498 4152032 37981.410

[6,] 3873070 23458.505 3837537 58992.267

[7,] 4113761 17419.423 4066210 64969.682

[8,] 0 0.000 0 0.000  

. which does the trick, I just loose all the labels. So my question is, can I create the full combined table, with the labels, from the start (i.e. one ftable & xtabs command), without the interim steps?  

Thanks  

Amnon

        [[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. Received on Wed 12 Mar 2008 - 14:05:05 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 Wed 12 Mar 2008 - 15:30:21 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