Re: [R] Fast Matrix Computation

2010-05-25 Thread David Neu
Thanks to everyone who responded! On Sun, May 23, 2010 at 1:32 AM, Jorge Ivan Velez wrote: > Yes, it should be. Thank you for pointing that out. Apologies for the noise. > > Regards, > Jorge > > > On Sun, May 23, 2010 at 1:07 AM, Berend Hasselman <> wrote: > >> >> >> Jorge Ivan Velez wrote: >> >

Re: [R] Fast Matrix Computation

2010-05-22 Thread Jorge Ivan Velez
Yes, it should be. Thank you for pointing that out. Apologies for the noise. Regards, Jorge On Sun, May 23, 2010 at 1:07 AM, Berend Hasselman <> wrote: > > > Jorge Ivan Velez wrote: > > > > # The same using a function foo > > foo <- function(A, B){ > > rA <- 1:nrow(A) > > rB <- 1:nrow(B) >

Re: [R] Fast Matrix Computation

2010-05-22 Thread Berend Hasselman
Jorge Ivan Velez wrote: > > # The same using a function foo > foo <- function(A, B){ > rA <- 1:nrow(A) > rB <- 1:nrow(B) > grid <- as.matrix(expand.grid(rA, rB)) > t(apply(grid, 1, function(x) abs(A[x[1], ] - B1[x[2], ]))) > } > > foo(A, B) > foo(A, B1) > > As usual, there might be be

Re: [R] Fast Matrix Computation

2010-05-22 Thread Jorge Ivan Velez
Hi David, Here are two suggestions, one that works for the example you provided and a second one for a more general case. # Your example A <- matrix(c(1, 2, 3, 4, 5, 6), byrow=TRUE, ncol=3) B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3) t(abs(t(A) - as.vector(B))) # More general case B1 <- structur

Re: [R] Fast Matrix Computation

2010-05-22 Thread Thomas Stewart
One possibility: n.A<-nrow(A) n.B<-nrow(B) abs( kronecker(A,rep(1,n.B)) - kronecker(rep(1,n.A),B) ) -tgs On Sat, May 22, 2010 at 3:20 PM, Shi, Tao wrote: > One way to do it: > > apply(B, 1, function(x) t(apply(A, 1, function(y) abs(y-x) )) ) > > > > > > - Original Message > > From: D

Re: [R] Fast Matrix Computation

2010-05-22 Thread Shi, Tao
One way to do it: apply(B, 1, function(x) t(apply(A, 1, function(y) abs(y-x) )) ) - Original Message > From: David Neu > To: r-help@r-project.org > Sent: Sat, May 22, 2010 10:35:32 AM > Subject: [R] Fast Matrix Computation > > Hi, I have two (large) matrices A and B of dimensions