[R] how to rename rows/columns of a matrix?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Jul 8 22:18:53 CEST 2003


apjaworski at mmm.com writes:

> This is what I would do:
> 
> cc <- NULL
> for(i in 1:ncol(x)) cc <- c(cc, paste("X", i, sep=''))
> colnames(x) <- cc
> 
> where x is your matrix.

R is a vectorized language:

colnames(x) <- paste("X", 1:ncol(x), sep='')

will do.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list