8
$\begingroup$

I want to have R display the data it gives me from the summary() function in a table so I can easily share this. I am currently just doing summary() in the console and then taking a screenshot, but I would rather have this generated as a nice table just like all of my graphs are. Any ideas?

$\endgroup$
4
$\begingroup$

If you have the R package Hmisc and a working latex installation you can do:

x=rnorm(1000)
y=rnorm(1000)
lm1=lm(y~x)
slm1=summary(lm1)
latex(slm1)

It works the same with datasets,

latex(summary(cars))
| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ An even better solution is to directly use summary.formula, e.g. print(summary(~ x + y), prmsd=TRUE, digits=1). The latex command assumes the OP has a working $\TeX$ installation. It is often convenient to just output plain text, like this: capture.output(print(summary(~ x + y), prmsd=TRUE, digits=1), file="out.txt"). $\endgroup$ – chl Aug 8 '12 at 1:01
  • 2
    $\begingroup$ Another approach to outputting plain text that works well is to use ?sink. Eg, sink(file=<name>, type="output"); <functions>; sink(), then a text file will exist in the working directory with whatever would have been the output of the functions used. $\endgroup$ – gung - Reinstate Monica Aug 8 '12 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.