How do I Create a table which looks something like this:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.220 22.850 0.000
groupTrt -0.371 0.311 -1.191 0.249
(Adjusted-R squared: 0.02)
From the following objects?
#DATA
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
A<-(lm(weight ~ group))
A<-summary(A)
B<-round(A$coefficients,3)
R<-paste("(Adjusted R-squared:",round(A$adj.r.squared,2),")")
I’m particularly interested cause I’ve been playing around with the outstanding R2wd which can output fantastic tables (at least for people who are restricted to Word in their workplace).
require(R2wd)
library(rcom)
wdGet(T)
wdNewDoc("c:\\temp\\This.doc")
wdTitle("My Analysis Title")
What I need to do next is to find a way to combine vectors A and R into a table-like object which will be formatted by the function wdTable(). It outputs B very neatly
try:
wdTable(B)
but I don’t quite know how to join B and R so that they make a suitable table. I guess it would be a matter of putting vector R in the 3rd row and 2nd col (as it appears above), but I’m having problems with it, and I’m not sure whether it will work with wdTable
I’ve found a related discussion on
this forum but it doesn’t really get to the heart of it. It outputs the whole thing as text rather than selected items as table.
Any help would be really appreciated
P.S. To run the R2wd You need to have the Word handle installed if you don’t run this
install.packages(c("R2wd","rcom"))
source("http://www.r-statistics.com/wp-content/uploads/2010/05/R-console-to-word.r.txt")
txtStart.2wd()
#Follow instructions (shows you commands to install the R handle)
txtStop.2wd(F)
i’d just try to rbind the line to the dataframe before calling wdtable(). you could split the string R and fill the cells in the new line with the elements.
like so: