[R] Matrix Column Names

Martin Maechler maechler at stat.math.ethz.ch
Tue Jul 13 10:32:28 CEST 2010


>>>>> "DN" == David Neu <david at davidneu.com>
>>>>>     on Mon, 12 Jul 2010 18:15:04 -0400 writes:

    DN> Hi, Is there a way to create a matrix in which the
    DN> column names are not checked to see if they are valid
    DN> variable names?

Why do you need that if you are really using a matrix, not a
data frame?

    DN> I'm looking something similar to the check.names
    DN> argument to data.frame.  

That's a good idea.
The relevant code inside data.frame() is simply

    if (check.names) 
        vnames <- make.names(vnames, unique = TRUE)

    DN> If so, would such an approach work for the sparse matrix
    DN> classes in the Matrix package.

Using function  make.names(), yes of course.

{but I'm still puzzled *why* you need this;
 If you want only want somewhat *short* names,
 I'd rather use

    vnames <- abbreviate(vnames, 8)

or variations of that such as
    vnames <- abbreviate(vnames, 8, method="both.sides")
or also
    vnames <- abbreviate(vnames, 8, strict=FALSE)

    DN> Many thanks!

you're welcome!

Martin Maechler, ETH Zurich



More information about the R-help mailing list