Re: [R] Prefix for colnames

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 21 Jul 2005 - 00:10:40 EST

jhainm@fas.harvard.edu writes:

> Hi,
>
> I would like to add a prefix to colnames in a matrix but I can't get the prefix
> option in colnames to work. What am I doing wrong?
>
> > X<-matrix(NA,3,4)
> > colnames(X)<-c("test","test","test","test")
> > colnames(X)<-colnames(X,prefix="PREFIX.")
> > X
> test test test test
> [1,] NA NA NA NA
> [2,] NA NA NA NA
> [3,] NA NA NA NA
>
> ?? I also tried with do.NULL set to FALSE but it still does not work.
>
> Thank you very much for your help!

Well

> colnames

function (x, do.NULL = TRUE, prefix = "col") {

    dn <- dimnames(x)
    if (!is.null(dn[[2]]))

        dn[[2]]
    else {

        if (do.NULL)
            NULL
        else paste(prefix, seq(length = NCOL(x)), sep = "")
    }
}

So if x has colnames that's what you get, irrespective of "prefix".

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Jul 21 00:22:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:51 EST