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')))
Yoav -
Here's one possibility:
wh = outer(rownames(mtrx),colnames(mtrx),
+ function(x,y)substr(x,nchar(x)-2,nchar(x)) ==
substr(y,nchar(y)-2,nchar(y)))
mtrx[wh]
[1] 1 6 8
If you knew that all of the row and column names were 4 characters long, it
would simplify to
On Apr 20, 2011, at 3:52 PM, yoav baranan wrote:
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 =
3 matches
Mail list logo