**70**wrote:

Hello,
please I need your help to make this loop works, its a permutation+metaanlysis on two sets of data, but i have an error message showing I need **foreach object**,
The idea is to get the results of N permutations (n.iter in my code) of the meta-anlysis of two sets of data, the association model is perforemd seperately on 1000 SNPs so for every merta analysis I need the results of 1000 SNPs in the two studies, that's why I am using foreach twice. Thanks for your help :

```
foreach(n.iter) %dopar%
foreach(i=22:7269) %dopar% {
Y_1<-as.vector(sample(V1,100,replace = F))
fit_1<-glm(Y_1~data[,i],data=data,family=binomial())
Y_2<-as.vector(sample(V2,100,replace = F))
fit_2<-glm(Y_2~data2[,i],data=data2,family=binomial())
sfit_y1<-summary(fit_y1)
sfit_y2<-summary(fit_y2)
p_yt<-sfit_y1$coefficients[3,4]
p_ct<-sfit_y2$coefficients[3,4]
p<-as.data.frame(p1=p_yt,n1=100,p2=p_ct,n2=100)
meta2<-metap(p,2,verbose="N")
meta<-(-log10(meta2[,2]))
return(meta)
}
```

and this is the original for loop I am trying to rewrite for parallelized computing as it takes too long time :

```
for (s in 1:n.iter) {
for(i in 22:nvar)
{p<-data.frame(p1=numeric(n.var),n1=rep(100,n.var),p2=numeric(n.var),n2=rep(100,n.var))
Y_y1<-as.vector(sample(data$PHENOTYPE,100,replace = F))
fit_y1<-glm(Y_y1~data[,i],data=data,family=binomial())
Y_y2<-as.vector(sample(data2$PHENOTYPE,100,replace = F))
fit_y2<-glm(Y_y2~data2[,i],data=data2,family=binomial())
j<-i-21
sfit_y1<-summary(fit_y1)
sfit_y2<-summary(fit_y2)
p$p1[3]<-sfit_y1$coefficients[3,4]
p$p2[3]<-sfit_y2$coefficients[3,4]
x<-metap(p[j,],2,verbose="N")
}
meta[s,j]<-x[,2]
}
write.csv2(meta,"meta.txt",row.names = F)
```

Thank you for your help !

Why are you using

`foreach`

twice ?56kThank you Kevin, I edited my post to explain better the objective of my code

70