I'm trying to reference the value in a previous calculation during the current one. I've tried using shift(), but it does not work when using the same variable.
x
1
2
3
5
1
I want to do something like this. I want shift(z) to refer to the previously calculated value of the same variable. If I run this, I get an error saying that object 'z' was not found.
dt[, z := 0.1 * x + 0.2 * shift(z)]
How do I do this without writing a loop?
dt[, z := 0.1 * x + 0.2 ][, z:= z * shift(z)]