[R] Prefix for colnames

Duncan Murdoch murdoch at stats.uwo.ca
Wed Jul 20 16:03:20 CEST 2005

On 7/20/2005 9:54 AM, jhainm at fas.harvard.edu wrote:
> 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?

The prefix argument is only used when there are no names and colnames is 
generating some.  You just want to use paste().

>> X<-matrix(NA,3,4)
>> colnames(X)<-c("test","test","test","test")

 > colnames(X) <- paste("PREFIX.", colnames(X), sep="")
 > X
      PREFIX.test PREFIX.test PREFIX.test PREFIX.test
[1,]          NA          NA          NA          NA
[2,]          NA          NA          NA          NA
[3,]          NA          NA          NA          NA

Duncan Murdoch

More information about the R-help mailing list