In str(summary(Model1)) we see that $coefficients has the value Std. Error Std. Error we want to remove.
lesserSummary <- function(x) { ## returns same as summary(x), but with "Std. Error" remove from coefficients. ## and class of object is "modifiedSummary" # grab the summary sm <- summary(x) # find which column is std error SE.indx <- which(colnames(sm$coefficients) == "Std. Error") # remove it sm$coefficients <- sm$coefficients[, -SE.indx] # give it some class class(sm) <- "modifiedSummary" # return it sm } xtable.modifiedSummary <- function (x, caption = NULL, label = NULL, align = NULL, digits = NULL, display = NULL, ...) { # x is a modifiedSummary object # This function is a modification of xtable:::xtable.summary.lm # Key Difference is simply the number of columns that x$coef is expected to have # (Here 3. Originally 4) x <- data.frame(x$coef, check.names = FALSE) class(x) <- c("xtable", "data.frame") caption(x) <- caption label(x) <- label align(x) <- switch(1 + is.null(align), align, c("r", "r", "r", "r")) digits(x) <- switch(1 + is.null(digits), digits, c(0, 4, 2, 4)) display(x) <- switch(1 + is.null(display), display, c("s", "f", "f", "f")) return(x) } xtable_mod <- function(x) { # Wrapper function to xtable.modified summary, calling first lesserSummary on x xtable(lesserSummary(x)) }
Example:
xtable_mod(model1) % latex table generated in R 2.15.1 by xtable 1.7-0 package % Sat Dec 8 23:44:54 2012 \begin{table}[ht] \begin{center} \begin{tabular}{rrrr} \hline & Estimate & t value & Pr($>$$|$t$|$) \\ \hline (Intercept) & 29.8007 & 30.70 & 0.0000 \\ crim & -0.3118 & -6.91 & 0.0000 \\ age & -0.0896 & -6.50 & 0.0000 \\ \hline \end{tabular} \end{center} \end{table}
Below are the steps taken to reach the above conclusion.
You can probably change the call to xtable, but first you need to do it a bit: start by viewing the source for xtable:
xtable # function (x, caption = NULL, label = NULL, align = NULL, digits = NULL, # display = NULL, ...) # { # UseMethod("xtable") # } # <environment: namespace:xtable>
We see that it just has a call to UseMethod() . So let's see what methods are available:
methods(xtable) # [1] xtable.anova* xtable.aov* xtable.aovlist* # [4] xtable.coxph* xtable.data.frame* xtable.glm* # [7] xtable.lm* xtable.matrix* xtable.prcomp* # [10] xtable.summary.aov* xtable.summary.aovlist* xtable.summary.glm* # [13] xtable.summary.lm* xtable.summary.prcomp* xtable.table* # [16] xtable.ts* xtable.zoo*
There are several. Please note that those that have an asterisk * are not visible.
The method being called is determined by the class of the object we are calling xtable on.
Suppose our result is Model1 . Let's look at his class: '
class(Model1) # [1] "lm"
So, the source we want to see is xtable.lm .
xtable.lm
Error? That's right, it is not visible. Therefore, we use the package name with triple colons. Note: please read the notice in the help file? ":"
xtable:::xtable.lm # function (x, caption = NULL, label = NULL, align = NULL, digits = NULL, # display = NULL, ...) # { # return(xtable.summary.lm(summary(x), caption = caption, label = label, # align = align, digits = digits, display = display)) # } # <environment: namespace:xtable>
Note that xtable.lm calls xtable.summary.lm and passes as its first argument a summary(x) , where x is our model.
So this brings us to two places to explore: summary and xtable.summary.lm