Printing big r matrix in Latex. I came out with this function which loops over rows.. is there any smarter way to do it? Is there a way to create a loop in Latex syntax?
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<echo=FALSE>>==
M <- head(mtcars)
tab_row <- function(i){paste0(
rownames(M)[i], " & ",
M[i,01], " & ",
M[i,02], " & ",
M[i,03], " & ",
M[i,04], " & ",
M[i,05], " & ",
M[i,06], " & ",
M[i,07], " & ",
M[i,08], " & ",
M[i,09], " & ",
M[i,10], " & ",
M[i,11], " \\\\\\\\ ", "\\\\hline \n")
}
tab <- rep("", nrow(M))
for (i in 1:nrow(M)) {tab[i] <- tab_row(i)}
tab <- paste(tab, collapse = '')
@
\begin{tabular}{ccccccccccccccc}
\Sexpr{tab}
\end{tabular}
\end{document}