[R] dependent nested for loops in R
Shaami
nz@h@@m @end|ng |rom gm@||@com
Sun Jan 31 05:26:21 CET 2021
Hi
I have very large dependent nested for loops that are quite expensive
computationally. It takes weeks and does not end to give me results. Could
anyone please guide how could I use apply function or any other suggestion
for such big and dependent loops in R? A sample code is as follows.
w = NULL
for(j in 1:1000)
{
x = rnorm(2000)
z = x[1]
for(i in 2:2000)
{
z = x[i]+5*z[i-1]
if(z>4 | z<1) {
w[j]=i
break
} else {
w[j] = 0
}
}
}
Thank you
[[alternative HTML version deleted]]
More information about the R-help
mailing list