Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psych - Getting factor loadings as data.frame for LaTeX export

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?

like image 715
bountiful Avatar asked Mar 23 '13 10:03

bountiful


1 Answers

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))
like image 63
Henrik Avatar answered Oct 13 '22 00:10

Henrik