r - Output of parApply different from my input -
i still quite new r (used program in matlab) , trying use parallel package speed calculations. below example trying calculate rolling standard deviation of matrix (by column) use of zoo package, , without parallelising codes. however, shape of outputs came out different.
# load library library('zoo') library('parallel') library('snow') # data z <- matrix(runif(1000000,0,1),100,1000) #this want calculate timing system.time(zz <- rollapply(z,10,sd,by.column=t, fill=na)) # trying achieve same output parallel computing cl<-makesockcluster(4) clusterevalq(cl, library(zoo)) system.time(yy <-parcapply(cl,z,function(x) rollapplyr(x,10,sd,fill=na))) stopcluster(cl)
my first output zz has same dimensions input z, whereas output yy vector rather matrix. understand can matrix(yy,nrow(z),ncol(z)) know if have done wrong or if there better way of coding improve this. thank you.
from documentation:
parrapply , parcapply return vector. if fun returns scalar result of length number of rows or columns: otherwise concatenation of returned values.
and:
parrapply , parcapply parallel row , column apply functions matrix x; may more efficient parapply less post-processing of result.
so, i'd suggest use parapply
.
Comments
Post a Comment