Hello, I have another stupid question. I hope you can give me a hint how to solve this: I have a list and one element is again a list containing matrices, all of the same dimensions. Now, I'd like to set the dimnames for all matrices: example code: m1 <- matrix(1:25, nrow=5) m2 <- matrix(26:50, nrow=5) # ... there can be much more than two matrices l <- list() l[[1]] <- list(m1,m2) r_names <- LETTERS[1:5] c_names <- LETTERS[6:10] ? how can I apply these names to any number of matrices within this list-list ? Ciao, Antje
how to set rownames / colnames for matrices in a list
3 messages · Alain Guillet, Antje
Hi, If all your matrices have the same size, you should work with an array and not with a list. Then you can use dimnames to set the names of the rows, columns, and so on.. Alain
Antje wrote:
Hello, I have another stupid question. I hope you can give me a hint how to solve this: I have a list and one element is again a list containing matrices, all of the same dimensions. Now, I'd like to set the dimnames for all matrices: example code: m1 <- matrix(1:25, nrow=5) m2 <- matrix(26:50, nrow=5) # ... there can be much more than two matrices l <- list() l[[1]] <- list(m1,m2) r_names <- LETTERS[1:5] c_names <- LETTERS[6:10] ? how can I apply these names to any number of matrices within this list-list ? Ciao, Antje
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Alain Guillet Statistician and Computer Scientist Institut de statistique - Universit? catholique de Louvain Bureau d.126 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50
Thanks for the hint with the "dimnames". I found a rather similar problem in
the mailing list solved like this:
x <- matrix(1:4,2)
y <- matrix(5:8,2)
z <- list(x,y)
nm <- c("a","b")
nms <- list(nm,nm)
z <- lapply(z,function(x){
dimnames(x)<-nms
x
})
Is there anything wrong using a list instead of an array???
Antje
Alain Guillet schrieb:
Hi, If all your matrices have the same size, you should work with an array and not with a list. Then you can use dimnames to set the names of the rows, columns, and so on.. Alain Antje wrote:
Hello, I have another stupid question. I hope you can give me a hint how to solve this: I have a list and one element is again a list containing matrices, all of the same dimensions. Now, I'd like to set the dimnames for all matrices: example code: m1 <- matrix(1:25, nrow=5) m2 <- matrix(26:50, nrow=5) # ... there can be much more than two matrices l <- list() l[[1]] <- list(m1,m2) r_names <- LETTERS[1:5] c_names <- LETTERS[6:10] ? how can I apply these names to any number of matrices within this list-list ? Ciao, Antje
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.