Hi I get a matrix with the columns named like "X13 X22 X1 X14 ...", i.e. not successively. That has it's good reasons, but now how can I rename the columns to "X1 X2 X3 ..."? Thanks a lot, David
If A is your matrix try: cnames(A) = paste("X", 1:ncol(A), sep="") -----Original Message----- From: David Andel [mailto:andel at ifi.unizh.ch] Sent: 08 July 2003 17:23 To: R-Project Subject: [R] how to rename rows/columns of a matrix? Hi I get a matrix with the columns named like "X13 X22 X1 X14 ...", i.e. not successively. That has it's good reasons, but now how can I rename the columns to "X1 X2 X3 ..."? Thanks a lot, David ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Sorry, that should have been "colnames" rather than cnames; i.e.: colnames(A) = paste("X", 1:ncol(A), sep="") -----Original Message----- From: David Andel [mailto:andel at ifi.unizh.ch] Sent: 08 July 2003 17:23 To: R-Project Subject: [R] how to rename rows/columns of a matrix? Hi I get a matrix with the columns named like "X13 X22 X1 X14 ...", i.e. not successively. That has it's good reasons, but now how can I rename the columns to "X1 X2 X3 ..."? Thanks a lot, David ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
For a matrix m with k columns: colnames(m) <- paste("X", 1:k, sep="") David -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of David Andel Sent: 08 July 2003 17:23 To: R-Project Subject: [R] how to rename rows/columns of a matrix? Hi I get a matrix with the columns named like "X13 X22 X1 X14 ...", i.e. not successively. That has it's good reasons, but now how can I rename the columns to "X1 X2 X3 ..."? Thanks a lot, David ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
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. Hope this helps, Andy __________________________________ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 ----- E-mail: apjaworski at mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 |---------+--------------------------------> | | "David Andel" | | | <andel at ifi.unizh.ch> | | | Sent by: | | | r-help-bounces at stat.m| | | ath.ethz.ch | | | | | | | | | 07/08/2003 11:22 | | | | |---------+--------------------------------> >-----------------------------------------------------------------------------------------------------------------------------| | | | To: "R-Project" <r-help at stat.math.ethz.ch> | | cc: | | Subject: [R] how to rename rows/columns of a matrix? | >-----------------------------------------------------------------------------------------------------------------------------| Hi I get a matrix with the columns named like "X13 X22 X1 X14 ...", i.e. not successively. That has it's good reasons, but now how can I rename the columns to "X1 X2 X3 ..."? Thanks a lot, David ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help