[R] get cells by the combination of their column and row names

From: yoav baranan <ybaranan_at_hotmail.com>
Date: Wed, 20 Apr 2011 22:52:40 +0300

Hi,
I have a (correlation) matrix and I want to select a subset of its cells depending on the combination of their column and row names. This illustrates my problem: mtrx <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, dimnames = list(c('c132','c432', 'c233'), c('r132','r233', 'r432')))> mtrx r132 r233 r432c132 1 4 7c432 2 5 8c233 3 6 9 At this point I want to compute the mean of the cells in which the column and the row names share the same suffix (i.e., the cells mtrx[1,1], mtrx[2,3], mtrx[3,2]). By suffix I mean the last three digits of the row/col name. I need a generic code (and not vec<-c(mtrx[1,1], mtrx[2,3], mtrx[3,2])) because I don't know in advance how many rows and columns I will have (currently 118). Thanks, Yoav

        [[alternative HTML version deleted]]



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. Received on Wed 20 Apr 2011 - 20:15:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 20:50:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive