Juan Antonio Balbuena
2012-Aug-30 14:24 UTC
[R] use row and col names of a matrix to create colnames of a new one.
Hello I would appreciate any help with the following: Given a matrix with col and row names, such as> matrix1 <- matrix(rnorm(16),4) > rownames(matrix1) <- LETTERS(1:4) > colnames(matrix1) <- letters[1:4] > matrix1a b c d A 1.6845882 -0.27809792 -0.874798414 -0.2143993 B -0.9283862 -1.50640703 -0.723568218 -0.4716539 C -1.6945380 -0.12336987 0.003299728 0.1413674 D -0.2715407 -0.05752609 -0.310539234 -1.1146264 I need to create a new matrix whose colnames are A-a, B-b, C-c and D-d. So the col and rownames of matrix1 are separated by an hyphen. It is probably very simple, but cannot find the way. Thank you very much for your time. -- View this message in context: http://r.789695.n4.nabble.com/use-row-and-col-names-of-a-matrix-to-create-colnames-of-a-new-one-tp4641829.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2012-Aug-30 14:55 UTC
[R] use row and col names of a matrix to create colnames of a new one.
On Aug 30, 2012, at 7:24 AM, Juan Antonio Balbuena wrote:>> matrix1 <- matrix(rnorm(16),4) >> rownames(matrix1) <- LETTERS[1:4] # fixed the coding error >> colnames(matrix1) <- letters[1:4]matrix2 <- matrix1 colnames(matrix2) <- paste(rownames(matrix1),colnames(matrix1),sep="-") matrix2 -- David Winsemius, MD Alameda, CA, USA