It depends on how big A is and how much memory you have. Here is one lazy way.
A <- aperm(aperm(A, c(2,1,3,4)) + x, c(2,1,3,4))
Bill Venables
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of huron
Sent: Thursday, 19 May 2011 1:47
Hi:
Reordering the dimensions, then doing a vectorized addition, then reordering
(back) again is faster, it seems.
> m <- 20; n <- 30; p <- 40; q <- 30
> a <- NA
> length(a) <- m * n * p * q
> dim(a) <- c(m, n, p, q)
> x <- 1:n
> a[1:m,,1:p,1:q] <- 0
> b <- a
>
> # Approach 1
> system.time({
+
2 matches
Mail list logo