On 01/02/2021 7:03 a.m., Shaami wrote:
z = NULL p = 0.25 x = rnorm(100) z[1] = p*x[1] + (1-p)*5 for(i in 2:100) { z[i] = p*x[i]+(1-p)*z[i-1] }
That's the same as p <- 0.25 x <- rnorm(100) z <- stats::filter(p*x, 1-p, init = 5, method="recursive") This leaves z as a time series; if that causes trouble, follow it with z <- as.numeric(z) Duncan Murdoch ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.