Another solution is to look into the code of summary.lm a few lines above where the (dim)names are assigned. Based on this, you may try
lma <- lm(dist ~ speed, data=cars) suma <- summary(lma) colnames(suma$coef) <- c(LETTERS[1:4]) printCoefmat(suma$coef) # prints what I expect suma dimnames(suma$coefficients) <- list(names(suma$coefficients), c(LETTERS[1:4])) suma You might also find reading the chapter on generic functions in the R-lang (R language definition) manual useful. Petr Christos Hatzis napsal(a): > Paul, > > Usually summary methods perform some computations if needed and then change > the class of the original object so that a print method can be called for > the new summary object. > > In this case, this is done at the end of the summary.lm method: > > ... > if (!is.null(z$na.action)) > ans$na.action <- z$na.action > class(ans) <- "summary.lm" > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > ans > } > > So then print.summary.lm does all the job displaying the summary.lm object. > To see that function do > > getAnywhere(print.summary.lm) > > Then you can then modify that function as needed. > > -Christos > > Christos Hatzis, Ph.D. > Nuvera Biosciences, Inc. > 400 West Cummings Park > Suite 5350 > Woburn, MA 01801 > Tel: 781-938-3830 > www.nuverabio.com > > > >> -----Original Message----- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of Paul Bailey >> Sent: Friday, March 09, 2007 9:34 AM >> To: [email protected] >> Subject: [R] understanding print.summary.lm and perhaps >> print/show in general >> >> I'm trying to understand how R prints summary.lm objects and >> trying to change it slightly for a summary function that >> calculates standard errors using an alternative method. >> >> I've found that I can modify a summary.lm object and then it >> prints the modified way but I want to change a few things in >> the print method that I think I might just be able to do. One >> is that I want the coefficients table to print a different >> header (other than "Std. Error"). I've tried changing the >> column name of the summary$coef matrix and this works for >> calls to printCoefmat but it still prints out "Std. Error" >> when I pass the summary.lm to the command line by itself. I >> don't understand this behavior. When I do this (enter an >> object on the command line by itself), does it then calls the >> print / show method associated with that objects class, in >> this case, summary.lm? Below is some sample code to reproduce >> the behavior I don't understand and a comment regarding the >> result I don't understand. >> >> Cheers, >> Paul >> >> ##### >> lma <- lm(dist ~ speed, data=cars) >> suma <- summary(lma) >> colnames(suma$coef) <- c(LETTERS[1:4]) >> printCoefmat(suma$coef) # prints what I expect suma # the >> above is the print behavior question regards, # why does the >> coefficients matrix have in its header # the usual "Estimate >> Std. Error t value Pr(>|t|)" >> # I expect "A B C D" as above in the call to printCoefmat >> >> ______________________________________________ >> [email protected] 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. >> >> > > ______________________________________________ > [email protected] 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. > -- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic ______________________________________________ [email protected] 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.
