1

Factor-analysis,

print(fa1, digits = 2, cutoff = 0.5, sort = TRUE)

shows me a nice table in the console. How can I save this table to a CSV file?

I tried write.csv and write.table with various combinations of arguments, but all gave the wrong result.

This works:

fa1 <- factanal(x, 3, rotation="varimax")

sink("tp.txt")  #write all output to file tp.txt
print(fa1, digits=2, cutoff=.5, sort=FALSE);
sink()  #stop sinking, =sink(NULL)

However, I want all values/numbers separated by commas.

Thanks Tim, sorry if this is a duplicate, but answering a question with another method that I cannot understand doesn't help. I don't want to redirect output to a variable, but to a CSV file. capture.output is not what I am looking for.

Thanks dcarlson! Not sure how to make your suggestion work. Is there a way to pipe the output to RMarkdown and then use a knit function?

Community
  • 1
  • 1
togedo
  • 31
  • 5
  • What is fa1? Include the full code. – user17144 Oct 22 '19 at 06:22
  • The functions `write.csv` and `write.table` are designed for tabular data, a row of column names, followed by multiple rows of values, one for each column name. The output from `factanal` does not follow that format so it is not likely you can get it to work. You could start with the code from `print.factanal` (`getAnywhere(print.factanal)`) and use that to compute the values you need and then use `print`/`cat` to a file to produce something that a spreadsheet program could import. – dcarlson Oct 22 '19 at 17:35

0 Answers0