Hello.

I've just started using R and am trying to figure out if the two codes
snippets below have the same output

gBest<-floor(runif(popsize,min=1,max=top))
velocity[i,j]<<-.4* velocity[i,j] + 1 * runif(1) * (pbestsVar[i,j] -
popVar[i,j]) + 1 * runif(1) * (archiveVar[gBest,j] - popVar[i,j])

and 

for (i in 1:popsize) {  
                for (j in 1:maxvar) {
                        gBest<-sample(top,size=1)                       
                        velocity[i,j]<<-.4* velocity[i,j] + 1 * runif(1) * 
(pbestsVar[i,j] -
popVar[i,j]) + 1 * runif(1) * (archiveVar[gBest,j] - popVar[i,j])
                        #velocity[i,j]<-.4* velocity[i,j] + 1 * .3722 * 
(pbestsVar[i,j] -
popVar[i,j]) + 1 * .3722 * (archiveVar[3,j] - popVar[i,j])
                }

many thanks


-- 
View this message in context: 
http://n4.nabble.com/For-loops-in-R-tp1015933p1015933.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.

Reply via email to