Skip to content
Prev 76382 / 398502 Next

Convert ftable to latex?

Hi Fredrik,

What you need to do is to massage your table a little to get it into the
appropriate structure and then use the rgroup and n.rgroup options.
Here's an example using the Titanic data that come with R. Note that
this is not necessarily (or even remotely likely?) the best way to get
your data into the shape required, but hopefully it shows you what, in
general, you need to do. You might find that you don't need to use
ftable at all, you might find other ways of creating the table you need.
In the example below, note in particular what x and x2 look like.
Age      Child     Adult
             Survived    No Yes    No Yes
Class Sex
1st   Male                0   5   118  57
      Female              0   1     4 140
2nd   Male                0  11   154  14
      Female              0  13    13  80
3rd   Male               35  13   387  75
      Female             17  14    89  76
Crew  Male                0   0   670 192
      Female              0   0     3  20
Sex No Yes  No Yes
1   Male  0   5 118  57
2 Female  0   1   4 140
3   Male  0  11 154  14
4 Female  0  13  13  80
5   Male 35  13 387  75
6 Female 17  14  89  76
7   Male  0   0 670 192
8 Female  0   0   3  20
+       title="",
+       rowname="",
+       rgroup=col1,
+       cgroup=c("", "Child", "Adult"),
+       n.cgroup=c(1, 2, 2),
+       n.rgroup=rep(2, 4)
+       )


HTH.

Dave
Fredrik Karlsson wrote: