# How to generate nice summary table?

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?

-

1
– chl♦ Aug 8 '12 at 1:12
You may want to read this awesome post on tables: Some notes on making effective tables by CV contributor @AndyW. Much of it is general information about tables (albeit awesome general information), but there is some specific to making tables in R w/ $\LaTeX$ as well. – gung Aug 8 '12 at 3:52

## 1 Answer

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))
````
-

1
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")`. – chl♦ Aug 8 '12 at 1:01
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. – gung Aug 8 '12 at 3:57
default
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9061439633369446, "perplexity_flag": "middle"}