title: Apply xtable() to a list of tables and a create pdf using knitr in R-studio
body: <p>I want to convert a list of tables to Latex using xtable() and create a pdf using Knitr in R-studio.</p>
  
  <p>I have tried to use llply() on the list but it does not work.</p>
  
  <p>Here is a list of tables:</p>
  
  <pre><code>library(plyr)
  library(xtable)
  Data &lt;- data.frame(a=rbinom(100,1,0.5), b=rbinom(100,1,0.3), c=rbinom(100,1,0.6))
  combos &lt;- combn(ncol(Data),2)
  TabelFn &lt;- function(x) {
    Table &lt;- addmargins(table(Data[, x[1]], Data[, x[2]]))
    return(Table)
  }
  Table &lt;- alply(.data=combos, .margins=2, .fun=TabelFn, .expand=TRUE)
  
  Table # list of tables
  </code></pre>
  
  <p>I tried to run llply() on it:</p>
  
  <pre><code>llply(Table, function(x) {xtable(x)})
  </code></pre>
  
  <p>And got this output:</p>
  
  <pre><code>$`1`
  % latex table generated in R 2.15.3 by xtable 1.7-1 package
  % Sat Apr 13 19:45:40 2013
  \begin{table}[ht]
  \centering
  \begin{tabular}{rrrr}
    \hline
   &amp; 0 &amp; 1 &amp; Sum \\ 
    \hline
  0 &amp; 48.00 &amp; 11.00 &amp; 59.00 \\ 
    1 &amp; 31.00 &amp; 10.00 &amp; 41.00 \\ 
    Sum &amp; 79.00 &amp; 21.00 &amp; 100.00 \\ 
     \hline
  \end{tabular}
  \end{table}
  
  $`2`
  % latex table generated in R 2.15.3 by xtable 1.7-1 package
  % Sat Apr 13 19:45:41 2013
  \begin{table}[ht]
  \centering
  \begin{tabular}{rrrr}
    \hline
   &amp; 0 &amp; 1 &amp; Sum \\ 
    \hline
  0 &amp; 27.00 &amp; 32.00 &amp; 59.00 \\ 
    1 &amp; 21.00 &amp; 20.00 &amp; 41.00 \\ 
    Sum &amp; 48.00 &amp; 52.00 &amp; 100.00 \\ 
     \hline
  \end{tabular}
  \end{table}
  
  $`3`
  % latex table generated in R 2.15.3 by xtable 1.7-1 package
  % Sat Apr 13 19:45:41 2013
  \begin{table}[ht]
  \centering
  \begin{tabular}{rrrr}
    \hline
   &amp; 0 &amp; 1 &amp; Sum \\ 
    \hline
  0 &amp; 40.00 &amp; 39.00 &amp; 79.00 \\ 
    1 &amp; 8.00 &amp; 13.00 &amp; 21.00 \\ 
    Sum &amp; 48.00 &amp; 52.00 &amp; 100.00 \\ 
     \hline
  \end{tabular}
  \end{table}
  </code></pre>
  
  <p>But Latex will not accept it. I guess it is because of the list-names like $<code>1</code> and $<code>2</code> and so on. This question <a href="https://stackoverflow.com/questions/7424159/xtable-output-for-a-list-of-tables">xtable output for a list of tables</a> explains a way to do it, but I was hoping there was a less complicated way of doing it?</p>