From maechler at stat.math.ethz.ch  Fri Dec  1 10:34:45 2006
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Fri, 1 Dec 2006 10:34:45 +0100
Subject: [Rd] printing coefficients with text
In-Reply-To: <20061130201755.GA8201@wheat.betterworld.us>
References: <20061130201755.GA8201@wheat.betterworld.us>
Message-ID: <17775.63285.29855.903217@stat.math.ethz.ch>

>>>>> "RossB" == Ross Boylan <ross at biostat.ucsf.edu>
>>>>>     on Thu, 30 Nov 2006 12:17:55 -0800 writes:

    RossB> I want to print the coefficient estimates of a model
    RossB> in a way as consistent with other output in R as
    RossB> possible. stats provides the printCoefmat function
    RossB> for doing this, but there is one problem.  I have an
    RossB> additional piece of textual information I want to put
    RossB> on the line with the other info on each coefficient.

that's not a real problem, see below

    RossB> The documentation for printCoefmat says the first
    RossB> argument must be numeric, which seems to rule this out.

it does say that (it says "x: a numeric matrix like object"
		  which includes data frames with factors)
but you are right that it does preclude a column of "character".

    RossB> I just realized I might be able to cheat by inserting
    RossB> the text into the name of the variable (fortunately
    RossB> there is just one item of text).  I think that's in
    RossB> the names of the matrix given as the first argument
    RossB> to the function.

yes; it's the rownames();
i.e., you'd do something like
      rownames(myx) <- paste(rownames(myx), format(mytext_var)))

which seems simple enough to me,
but it only works when the "text" is the first column

    RossB> Are there any better solutions?  Obviously I could
    RossB> just copy the method and modify it, but that creates
    RossB> duplicate code and loses the ability to track future
    RossB> changes to printCoefmat.

As original author of printCoefmat(), I'm quite willing to
accept and incorporate a patch to the current function
definition (in https://svn.r-project.org/R/trunk/src/library/R/anova.R),
if it's well written.

As a matter of fact, I think already see how to generalize printCoefmat()
to work for the case of data frame with character columns
[I would not want a character matrix however; since that would mean
 going numeric -> character -> numeric -> formatting (i.e character)
 for the 'coefficients' themselves].

Can you send me a reproducible example?
or at least an *.Rda file of a save()d such data frame?

    RossB> Thanks.  Ross Boylan

You're welcome,
Martin Maechler, ETH Zurich



[Rd] printing coefficients with text
Martin Maechler