Question

I am using the psych package's fa command for factor analysis, and so have an object of class fa. I can query the loadings with fac$loadings, but I want to only extract the table containing the loadings, so I can use xtable (or similar) to convert it into LaTeX format.

Example code:

library(psych)
library(xtable)
data(bfi)
fac <- fa(r=cor(bfi, use="complete.obs"), nfactors=5, fm="ml", rotate="none")
fac$loadings
ld <- someMagicalFunction(fac$loadings)
xtable(ld)

Can anyone tell me what I can use for someMagicalFunction?

Was it helpful?

Solution

When you look at fac$loading, you see that it is a S3 object. Removing the class attribute gives you a matrix which can then be passed to xtable:

str(fac$loadings)
class(fac$loadings)

xtable(unclass(fac$loadings))

OTHER TIPS

That works fine.

An alternative is to use the fa2latex function in psych:

Using your example:

library(psych)
fac <- fa(bfi,5)
fa2latex(fac)

will give you an APA ready LaTeX table.

Bill

The result of xtable is in HTML language. If you want to save it as a file, you can use:

print.xtable(x, type="HTML", file="table.html")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top