[R] Help for numbers close to 1 in R

2010-02-13 Thread cjmr
Hi all. I have a problem with adding 1 and very small numbers ex: >p=1e-49 >1+p [1] 1 My problem comes from some values of x for the value: 1-exp(-sum((x-1/sqrt(3))^2)) the return values are always equivalent. Please help Thanks -- View this message in context: http://n4.nabble.com/Help-

Re: [R] Odp: For loops in R

2010-01-18 Thread cjmr
4 * velocity + rmat * (pbestsVar - popVar) + rmat2 * (archiveVar[rindex,] - popVar) Also, do the apply methods perform better than for loops given the same function? sample: apply(x, fun) and for (i in 1:length(x)) fun(x[i]) cheers cjmr -- View this message in context: http://n4.nabble.com/Fo

Re: [R] Odp: For loops in R

2010-01-18 Thread cjmr
Hello Sorry for the confusion Here are additional details. velocity, popVar, archiveVar,pbestsVar are matrices with dimension of 500 row, 2 col matrix. I want to assign new values for each velocity[i,j] using the formula below: *0.4 * velocity[i,j] + 1 * randomvalue * (pbestsVar[i,j] - popVar[

[R] For loops in R

2010-01-17 Thread cjmr
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