Suppose you have two vectors, which contain row and column indices of
some elements of an array. Is there a good way to find the
corresponding elements?
For example:
> test <- matrix(1:20, ncol=4)
> test.i <- c(1,3,5)
> test.j <- c(4,2,2)
Is there a better way to get this answer?
> diag(test[test.i,test.j])
[1] 16 8 10
Thanks,
Carlisle
********************************************************
* William Carlisle Thacker *
* *
* Atlantic Oceanographic and Meteorological Laboratory *
* 4301 Rickenbacker Causeway *
* Miami, Florida 33149 USA *
* Office: (305) 361-4323 *
* Fax: (305) 361-4392 *
********************************************************
|