[R] how to save summary(lm) and anova (lm) in format?

Paul Johnson pauljohn32 at gmail.com
Tue Jul 6 17:19:56 CEST 2010


There are R packages that can make nice R regression tables in LaTeX
documents. I've used memisc and its good, there is also "apsrtable"
and the old standby xtable.  Also I use my own function "outreg", but
that's just a 'not invented here' attitude.

Your problem is that you need this to go into Word, in which case I
think a reasonable strategy is to create html output in R and then in
Word you can use "paste special" HTML and it will bring in the html as
a Word table.

I recently made a presentation about this, you might scan down to the
end where I have the html example for the poor-pitiful Word users of
the world:

http://pj.freefaculty.org/SummerCamp2010/regression2.pdf

Look down around slide 75

pj


On Fri, Jul 2, 2010 at 12:34 PM, Yi <liuyi.feier at gmail.com> wrote:
> Hi, folks,
>
> I would like to copy the output of summary(lm) and anova (lm) in R to my
> word file. But the output will be a mess if I just copy after I call summary
> and anova.
>
> #####################
> x=rnorm(10)
> y=rnorm(10,mean=3)
> lm=lm(y~x)
> summary(lm)
>
> Call:
> lm(formula = y ~ x)
> Residuals:
>      Min        1Q    Median        3Q       Max
> -1.278567 -0.312017  0.001938  0.297578  1.310113
> Coefficients:
>            Estimate Std. Error t value Pr(>|t|)
> (Intercept)   2.5221     0.2272  11.103 3.87e-06 ***
> x            -0.5988     0.2731  -2.192   0.0597 .
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Residual standard error: 0.7181 on 8 degrees of freedom
> Multiple R-squared: 0.3753,     Adjusted R-squared: 0.2972
> F-statistic: 4.807 on 1 and 8 DF,  p-value: 0.0597
> ####################
>
> How can I get the exact ouput as shown in R but not as the above?
>
>
> Thanks.
>
> Yi
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas



More information about the R-help mailing list