Re: [R] Multiply each depth level of an array with another vector element

2010-08-06 Thread Wu Gong
It's interesting that sweep is the slowest one comparing to replicate and rep :) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Multiply-each-depth-level-of-an-array-with-another-vector-element-tp2315537p2316586.html Sent from the R help mailing list archive a

Re: [R] Multiply each depth level of an array with another vector element

2010-08-06 Thread Greg Snow
5, 2010 2:00 PM > To: r-help@r-project.org > Subject: [R] Multiply each depth level of an array with another vector > element > > Suppose > > x <- array(c(1,1,1,1,2,2,2,2), dim = c(2,2,2)) > > y <- c(5, 10) > > > > Now I would like to multiply x[, ,

Re: [R] Multiply each depth level of an array with another vector element

2010-08-05 Thread Wu Gong
I have only achieved a half improvement. x <- array(1:2400*1, dim = c(200,300,400)) y <- 1:400*1 ptm <- proc.time() z <- x*as.vector(t(replicate(dim(x)[1]*dim(x)[2], y[1:dim(x)[3]]))) "replicate:" proc.time() - ptm x <- array(1:2400*1, dim = c(200,300,400)) y <- 1:400*1 ptm <- proc.time

[R] Multiply each depth level of an array with another vector element

2010-08-05 Thread Maurits Aben
Suppose x <- array(c(1,1,1,1,2,2,2,2), dim = c(2,2,2)) y <- c(5, 10) Now I would like to multiply x[, , 1] with y[1] and x[, , 2] with y[2]. Possible solution is a for-loop: for (i in 1:2) { x[, , i] * y[i] } Another possible solution is this construction: as.vector(t(replicate(nrow(