[R] selecting vector elements using matrices and combining the results

2009-07-28 Thread Jean V Adams
(I'm resending this, because there seemed to be a problem with my previous attempt.) I've been scratching my head over this one for too long. I'm hoping someone out there can solve this riddle. I have two vectors of characters, v1 and v2, both of length L, and two matrices of logicals, m1 and

Re: [R] selecting vector elements using matrices and combining the results

2009-07-28 Thread Gabor Grothendieck
Here is a slight simplification: nr <- nrow(m1); nc <- ncol(m1) lapply(1:nr, function(i) cbind(v1, v2)[cbind(1:nc, (m1+2*m2)[i,])]) On Tue, Jul 28, 2009 at 1:36 PM, Gabor Grothendieck wrote: > Try this: > >> lapply(1:3, function(i) cbind(v1, v2)[cbind(col(m1)[i,], (m1+2*m2)[i,])]) > [[1]] > [1]

Re: [R] selecting vector elements using matrices and combining the results

2009-07-28 Thread Gabor Grothendieck
Try this: > lapply(1:3, function(i) cbind(v1, v2)[cbind(col(m1)[i,], (m1+2*m2)[i,])]) [[1]] [1] "A" "b" "D" "f" [[2]] [1] "C" "E" [[3]] [1] "D" "e" On Tue, Jul 28, 2009 at 12:48 PM, Jean V Adams wrote: > I've been scratching my head over this one for too long.  I'm hoping > someone out there c

Re: [R] selecting vector elements using matrices and combining the results

2009-07-28 Thread Steve Lianoglou
Hi, On Jul 28, 2009, at 12:48 PM, Jean V Adams wrote: I've been scratching my head over this one for too long. I'm hoping someone out there can solve this riddle. I have two vectors of characters, v1 and v2, both of length L, and two matrices of logicals, m1 and m2, both of dimension N*L. Th

[R] selecting vector elements using matrices and combining the results

2009-07-28 Thread Jean V Adams
I've been scratching my head over this one for too long. I'm hoping someone out there can solve this riddle. I have two vectors of characters, v1 and v2, both of length L, and two matrices of logicals, m1 and m2, both of dimension N*L. The first matrix of logicals corresponds to the first vec