Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread Rui Barradas
Kevin, Your problem seems to have three restrictions: (1) abs(x[i] - x[i-1]) >= delta (2) y[i] >= x[i] and (3) minimize sum(y-x). If this is the case I believe I have a better solution, with a smaller sum and in much less time. The problem is restriction (2). If the diffs are negative you can't su

Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread Rui Barradas
Kevin, I'm sorry, but my code has a bug The correction is: 1) delete the two lines with 'ix' 2) replace them with for(i in 2:n) if(abs(x[i] - x[i-1]) < delta) x[i] <- x[i-1] + delta That's it. The problem is that it's back to slowness. Sorry, once again, Rui Barradas

[R] Lagged values problem requiring short solution time

2011-12-11 Thread Kevin Ummel
Hello, I am hoping someone can help tackle the problem below, for which I require a fast solution. It feels like there should be an elegant approach, but I am drawing blanks. Take a vector 'x' with random values > 0: x = runif(10,1,5) Assume some reasonably small positive value 'delta': delt