Search code examples
rstatisticsknitrsweavereproducible-research

R: t.test output for LaTex


I wonder if there is any function to redirect the output of t.test to LaTeX. Some thing like this

library(xtable)
xtable(t.test(extra ~ group, data = sleep))

Solution

  • This does the trick.

    library(schoRsch)
    library(xtable)
    
    T.Test <- t.test(extra ~ group, data = sleep)
    xtable(
      t_out(toutput=T.Test, n.equal = TRUE, welch.df.exact = TRUE, welch.n = NA,
        d.corr = TRUE, print = TRUE)
        )
    
    
    
                          Test                            Results
    1 Welch Two Sample t-test: t(17.78) = -1.86, p = .079, d = NA
    % latex table generated in R 3.1.1 by xtable 1.7-3 package
    % Mon Aug 25 21:01:13 2014
    \begin{table}[ht]
    \centering
    \begin{tabular}{rll}
      \hline
     & Test & Results \\ 
      \hline
    1 & Welch Two Sample t-test: & t(17.78) = -1.86, p = .079, d = NA \\ 
       \hline
    \end{tabular}
    \end{table}