Re: [R] Problem at subsetting matrix by using dimnames

2009-09-21 Thread Agustin Lobo
Thanks a lot. Based on your suggestions, would the following diag(mitest[c("a", "b", "c"), c("b", "c", "b")]) work in general? (it does for my example). If so, I would prefer this form as I understand it better. Agus Henrique Dallazuanna wrote: Try this: mapply(function(x, y)mitest[x, y], c

Re: [R] Problem at subsetting matrix by using dimnames

2009-09-02 Thread Henrique Dallazuanna
Try this: mapply(function(x, y)mitest[x, y], c("a", "b", "c"), c("b", "c", "b")) or diag(`[`(mitest, i = c("a", "b", "c"), j = c("b", "c", "b"))) On Wed, Sep 2, 2009 at 6:57 AM, Agustin Lobo wrote: > Given: > > > mitest <- matrix(1:16,ncol=4) > > dimnames(mitest)[[1]] <- c("a","b","c","d")

[R] Problem at subsetting matrix by using dimnames

2009-09-02 Thread Agustin Lobo
Given: > mitest <- matrix(1:16,ncol=4) > dimnames(mitest)[[1]] <- c("a","b","c","d") > dimnames(mitest)[[2]] <- c("a","b","c","d") > mitest a b c d a 1 5 9 13 b 2 6 10 14 c 3 7 11 15 d 4 8 12 16 I can do: > mitest[cbind(c(1,2,3),c(2,3,2))] [1] 5 10 7 but using the names does not work: > m