Actually, you'll need to identify the values of the foreach loop in the for
loop for it to work...
require(doParallel)
require(foreach)
set.seed(666)
xyz<-as.data.frame(cbind(x=rep(rpois(5,10),2)+1,
y=rep(rpois(5,10),2)+1,z=round(runif(10, min=-3, max=40),2)))
xyz$mins<-rep(NA, nrow(
Hiya,
This now works...
test<-foreach(i=unique(xyz[,1]), .combine=rbind, .verbose=T) %dopar% {
for( j in unique(xyz[,2])) {
xyz[xyz[,2] == j & xyz[,1] == i ,4]<-min(xyz[xyz[,2] == j & xyz[,1] ==
i,3])
nr=nrow(xyz[xyz[,2] == j & xyz[,1] == i ,4])
}
retu
Hiya,
Yes that would work, also an aggregate with merge can work, but I really would
like to make this a parallel calculation with farming out the first loop to
different workers and put the output together again into the data.frame with
additional columns. This will speed up work with very larg
Hi
I may be completely wrong but isn't it work for ave? With your example I get
> fac<-interaction(xyz[,1], xyz[,2], drop=TRUE)
> xyz[,4]<-ave(xyz$z, fac, FUN= min)
> head(xyz)
x y z mins
1 13 15 1.97 -2.91
2 17 9 14.90 -2.81
3 9 10 34.68 -1.97
4 17 6 4.26 -2.63
5 3 12 0.12 0.12
4 matches
Mail list logo