psych (version 1.3.2)

df2latex: Convert a data frame, correlation matrix, or factor analysis output to a LaTeX table

Description

A handy helper function to convert data frames or matrices to LaTeX tables. Although Sweave is the preferred means of converting R output to LaTeX, it is sometimes useful to go directly from a data.frame or matrix to a LaTeX table. cor2latex will find the correlations and then create a lower (or upper) triangular matrix for latex output. fa2latex will create the latex commands for showing the loadings and factor intercorrelations. As the default option, tables are prepared in an approximation of APA format.

Usage

df2latex(x,digits=2,rowlabels=TRUE,apa=TRUE,short.names=TRUE,font.size ="scriptsize",
  heading="A table from R",caption="df2latex")
cor2latex(x,digits=2,rowlabels=TRUE,lower=TRUE,apa=TRUE,short.names=TRUE,
     font.size ="scriptsize",heading="A correlation table from R",caption="cor2latex")
fa2latex(f,digits=2,rowlabels=TRUE,apa=TRUE,short.names=FALSE,font.size ="tiny",
    heading="A factor analysis table from R",caption="fa2latex") 
irt2latex(f,digits=2,rowlabels=TRUE,apa=TRUE,short.names=FALSE,font.size ="tiny",
     heading="An IRT factor analysis table from R",caption="fa2latex")

Arguments

x
A data frame or matrix to convert to LaTeX. If non-square, then correlations will be found prior to printing in cor2latex
digits
Round the output to digits of accuracy. NULL for formatting character data
rowlabels
If TRUE, use the row names from the matrix or data.frame
short.names
Name the columns 1 .. N to save space
apa
If TRUE formats table in APA style
font.size
e.g., "scriptsize", "tiny" or anyother acceptable LaTeX font size.
heading
The label appearing at the top of the table
caption
The table caption
lower
in cor2latex, just show the lower triangular matrix
f
The object returned from a factor analysis using fa or irt.fa.

Value

  • A LaTeX table

See Also

The many LaTeX conversion routines in Hmisc.

Examples

Run this code
df2latex(Thurstone,rowlabels=FALSE,apa=FALSE,short.names=FALSE,caption="Thurstone Correlation matrix")
df2latex(Thurstone,heading="Thurstone Correlation matrix in APA style")

df2latex(describe(sat.act)[2:10],short.names=FALSE)
cor2latex(Thurstone)
cor2latex(sat.act,short.names=FALSE)
fa2latex(fa(Thurstone,3),heading="Factor analysis from R in quasi APA style")

Run the code above in your browser using DataCamp Workspace