About these ads

R: Convert table R2LaTeX

R and LaTeX work very well together. Let me show you how to generate a LaTeX table from a R variable.

First, install the xtable package if it’s not already.

install.packages("xtable")

Next load the package and create the tex-file with the table variable result. For illustration purposes, I create a matrix with random values.

library(xtable)
result <- replicate(6, rnorm(10)) # random matrix
print(xtable(result), type="latex", file="output.tex")

Since you probably don’t need an object that holds the LaTeX code, creating and writing the code to a file is combined in one command.

Note: You can control the number of digits using:

xtable(result, digits=-3)

The minus puts numbers into scientific format.

About these ads

2 Responses to “R: Convert table R2LaTeX”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 712 other followers

%d bloggers like this: