try:
> a = c(1, 4, 5)
> b = c(2, 6, 7)
> 
> m <- matrix(1:49,7,7)
> m[cbind(a,b)]   # 'array' indexing
[1]  8 39 47
> m
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    1    8   15   22   29   36   43
[2,]    2    9   16   23   30   37   44
[3,]    3   10   17   24   31   38   45
[4,]    4   11   18   25   32   39   46
[5,]    5   12   19   26   33   40   47
[6,]    6   13   20   27   34   41   48
[7,]    7   14   21   28   35   42   49
> 


 
Jim Holtman

"What is the problem you are trying to solve?"



----- Original Message ----
From: yoooooo <magno_yu@ml.com>
To: r-help@stat.math.ethz.ch
Sent: Thursday, March 1, 2007 4:28:02 PM
Subject: [R] Simplest question ever...


Let's say i have

a = c(1, 4, 5)
b = c(2, 6, 7)

and i have matrix m, what's an efficient way of access
m[1, 2], m[4, 6], m[5, 7]
like of course m[a, b] = is not going to do, but what's an expression that
will allow me to have that list? 

Thanks!
-- 
View this message in context: http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@stat.math.ethz.ch 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.


 
____________________________________________________________________________________

Access over 1 million songs.

	[[alternative HTML version deleted]]

