[R] dependent nested for loops in R
Shaami
nz@h@@m @end|ng |rom gm@||@com
Mon Feb 1 17:54:28 CET 2021
Hi Duncan
It worked. Thank you.
Best Regards
On Mon, Feb 1, 2021 at 6:26 PM Duncan Murdoch <murdoch.duncan using gmail.com>
wrote:
> 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
>
>
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list