Let\'s say there is an R matrix x
:
x <- structure(c(2, 3, 5, 7, 9, 12, 17, 10, 18, 13), .Dim = c(5L,2L), .Dimnames = list(NULL, c(\"X1\", \"X
For a future reference, here is the function that I wrote myself later:
matrix2latex <- function(matr) {
printmrow <- function(x) {
cat(cat(x,sep=" & "),"\\\\ \n")
}
cat("\\begin{bmatrix}","\n")
body <- apply(matr,1,printmrow)
cat("\\end{bmatrix}")
}
It doesn't require an external package. For some reason the apply
produced NULL at the end of the output (the actual return?). This was solved by assigning the return to the body
variable, which is otherwise of no use. The next task is to render the output of that function in LaTeX within knitr.