[R] array indices in synced vectors

2005-09-08 Thread Erich Neuwirth
Let us start with the following definitions xxx<-rep(c(1,2),times=5) yyy<-rep(c(1,2),each=5) a<-c(11,12) b<-matrix(1:4,2,2) a[xxx] produces [1] 11 12 11 12 11 12 11 12 11 12 b[xxx,yyy] produces [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]11111333

Re: [R] array indices in synced vectors

2005-09-08 Thread Thomas Lumley
On Thu, 8 Sep 2005, Erich Neuwirth wrote: > > sapply(1:length(xxx),function(x)b[xxx[x],yyy[x]]) > does what I need and produces > [1] 1 2 1 2 1 4 3 4 3 4 > > Is there a function taking xxx,yyy, and b as arguments > producing the same result? b[cbind(xxx,yyy)] > Essentially, I am asking for a vers