[R] ftable and xtabs

Henrique Dallazuanna wwwhsd at gmail.com
Wed Mar 12 15:49:17 CET 2008


Please see the footer of email:

>  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.

try this


cbind(write.ftable(camel, quote=F),
         write.ftable(dunhill, quote=F))[-(1:length(c(camel, dunhill)))]



On 12/03/2008, Amnon Melzer <amnon.melzer at eighty20.co.za> wrote:
> 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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list