Quantcast
Channel: How to repeat a for loop in R for n times? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to repeat a for loop in R for n times?

$
0
0

I am trying to repeat a for loop in R for a fixed number of times. Here is a sample of the code I want to repeat

for (i in 1:nrow(data)) {  if (i>130){    data$deltas[i]=-((-data$p[i]))*data$alphas[i]  }  else  {    data$deltas[i]=      ((-(((data$p[i+1])-(data$p[i])))*data$alphas[i]) + data$deltas[i+1])  }}

I do not have any conditions that need to be met, just need to run the same code over the same dataset n times.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>