title: Test statistic (e.g. chisquare test) inside latex table using the tables-package in R/Knitr/Rstudio
body: <p>I would like to use the tabular()-function from the tables-package to do a cross-tabulation of two variables (e.g. v1 and v2), and present the p-value of the chisq-test in the table. It is easy to get the crosstabulation, but I cant get the p-value inside the table. This is what I've been trying, without any luck:</p>
  
  <p><img src="https://i.stack.imgur.com/ANxpT.png" alt="enter image description here"></p>
  
  <pre><code>\documentclass{article}
  
  \begin{document}
  
  &lt;&lt;echo=TRUE,message=FALSE&gt;&gt;=
  library(Hmisc)
  library(tables)
  v1 &lt;- sample(letters[1:2],200,replace=TRUE)
  v2 &lt;- sample(month.name[1:3],200,replace=TRUE)
  df &lt;- data.frame(v1,v2)
  @
  
  It is straight forward to get the crosstabulation:
  &lt;&lt;results='asis'&gt;&gt;=
  latex(   tabular(    Factor(v1)   ~   Factor(v2)      , data=df)  )
  @
  
  But I cant get the p-value inside the table:
  
  &lt;&lt;results='asis'&gt;&gt;=
  latex(   tabular(    Factor(v1)*chisq.test(v1,v2)$p.value   ~   Factor(v2)      , data=df)  )
  @
  
  \end{document}
  </code></pre>