[R] Replace for loop when vector calling itself

rivercode aquanyc at gmail.com
Mon Mar 7 21:44:58 CET 2011


Hi,

Thanks for your replies.

In summary:

1.   Replace code with c(0, cumsum(diff(theoP)) ).   This is indeed correct
and I had not realized it !!

>> d = vector(mode = "numeric", length= len)
>> d[1] = 0
>> if (len>1) for (i in 2:len) { d[i] = d[i-1] + theoP[i] - theoP[i-1] }

2.  How to create recursive vector, eg. vector = previous vector * new_data
... suggested to look at the filter() function.

Thanks for your replies.

Cheers,
Chris

--
View this message in context: http://r.789695.n4.nabble.com/Replace-for-loop-when-vector-calling-itself-tp3338383p3339938.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list