On Thu, Aug 2, 2012 at 8:16 AM, Cloneberry <clonebe...@gmail.com> wrote: > Hi, > just during these vacation days, I'm trying to approach with multicore > package > and I have some troubles with foreach. > What I'm trying to do is to extract a data in coordinate (ii,jj) from a > matrix2, > only if the data in the same coordinate in matrix1 is ==1.
I think you're making this far too hard -- subsetting is a relatively cheap operation and shouldn't require this sort of parallelization: matrix2[matrix1 == 1] matrix1 == 1 will create a boolean (TRUE/FALSE) matrix which you then use to pick out a subset of matrix2. Best, Michael > Make this with a nested "for" take a lot of time because I have thousand of > values. > > ex. > Binary_hex = NULL > foreach(ii=1:nrow(matrix2)) %:% foreach(jj=1:ncol(matrix2)) %dopar% > {when(matrix2[ii,jj] == 1) %:% {Binary_hex <- c(Binary_hex, > matrix1[ii,jj])}} > > During this operation... computer don't work in multicore and the process > take a lot of time, > just like a simple nested for. I think the mistake is in the "when" > parameter because if I substitute > the "when" with another function (like "sqrt") it work greatly and fast. > Please, give me some suggestion, also with different way. > Thank you in advance. > Max > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Filter-a-matrix-with-a-matrix-HELP-tp4638871.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.