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
?sweep -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Maurits Aben > Sent: Thursday, August 05, 2010 2:00 PM

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