Sandor Benczik
2009-Jun-23 09:13 UTC
[R] Vectorize linear autoregression with variable coefficients
This might be obvious to some, but I can't find a neat way to do it: Say I have two (very long) numerical vectors a & b of the same length representing variable coefficients of a linear autoregression. I want to calculate vector x defined by x[1] <- b[1] for (n in 2:length(a)) x[n] <- a[n]*x[n-1] + b[n] Is there a way to do this vectorially, i.e. without using the 'for' loop? Thanks, Sandor