Вопрос

I've a list of tables and want to sweave it for LaTex output. Here is the code:

Data <- esoph[ , 1:3]
library(plyr)
combos <- combn(ncol(Data),2)

TabelFn <- function(x) {
  Table <- addmargins(table(Data[, x[1]], Data[, x[2]]))
  return(Table)
  }

Table <- alply(.data=combos, .margins=2, .fun=TabelFn, .expand=TRUE)
library(xtable)

The list Table has three contingency tables in this case and I can sweave the output to LaTex using this code:

<< label = tabTable, echo = FALSE, results = tex >>=
print(xtable(Table[1]$'1', caption = "Contingency table for agegp and alcgp", label = "tab:Table[1]",
             digits = c(0, rep(0, ncol(Table[1]$'1'))),
             align = paste(paste("l|", paste(rep("r", ncol(Table[1]$'1')-1), collapse =     ''), sep = ""), "l", sep = "")),
      table.placement = "tbp", caption.placement = "top",
      hline.after = c(-1, 0, nrow(Table[1]$'1')))
@

To send the output of three contingency tables I've to write three such commands. In this case it is feasible. But for my actual data I've many contingency tables. I'd like to know how to send all contingency tables more efficiently. One choice is to just print the list Table without xtable. But I'd like to have the contingency table in nice output format. Thanks for your time and help.

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top