[R] Fast Matrix Computation
Berend Hasselman
bhh at xs4all.nl
Sun May 23 07:07:01 CEST 2010
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 better and faster ways to do this.
>
> HTH,
> Jorge
>
Shouldn't the B1 in the last line of the function 'foo' be B (the second
argument of the function)?
Berend
--
View this message in context: http://r.789695.n4.nabble.com/Fast-Matrix-Computation-tp2227321p2227624.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list