cjmr
January 17th, 2010, 01:33 AM
Hello!
I just started R and am trying to convert C code to it. I need help in checking if the two codes below are the same.
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])
}
}
and
i<-seq(1,popsize)
j<-seq(1,maxvar)
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])
Also does using lapply instead of a for loop increase performance?
many thanks
I just started R and am trying to convert C code to it. I need help in checking if the two codes below are the same.
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])
}
}
and
i<-seq(1,popsize)
j<-seq(1,maxvar)
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])
Also does using lapply instead of a for loop increase performance?
many thanks