title: For loop with dynamic input
body: <p>I am trying to create a dynamic input that I can easily change that will be used inside a for loop. Inside a for loop that I am using, there is a variable, let's call it <code>b</code>, that is used multiple times, and every time I want to slightly change the value stored in <code>b</code>, I have to go through and find each instance of <code>b</code> and change it. I am hoping to create an input outside of the for loop that I can use to update <code>b</code> inside the for loop.</p>
  <p>This is a very simplified example of what I am currently doing.</p>
  <pre><code>df &lt;- data.frame(replicate(3,sample(0:100,10,rep=TRUE)))
  for (i in c(1:nrow(df))){
    nm &lt;- i
    if (nm == nrow(df)) {
      next
    } else {
      x &lt;- df[c((nm):(nm+1)),]
      b &lt;- x$X1[1]
      print(b &gt; x$X2[2])
    }
  }
  </code></pre>
  <p>Here is an example of what I am trying to do, however, in this example the input does not work because dateframe <code>x</code> is not yet created. Some more examples of the inputs could be <code>b &lt;- x$X1[2]</code>, <code>b &lt;- x$X2[1]</code>, <code>b &lt;- x$X3[2]</code>, etc</p>
  <pre><code>df &lt;- data.frame(replicate(3,sample(0:100,10,rep=TRUE)))
  
  ##input
  
  b &lt;- x$X1[1]
  
  ###
  
  for (i in c(1:nrow(df))){
    nm &lt;- i
    if (nm == nrow(df)) {
      next
    } else {
      x &lt;- df[c((nm):(nm+1)),]
      print(b &gt; x$X2[2])
    }
  }
  </code></pre>
  <p>I was looking at this post <a href="https://stackoverflow.com/questions/57454085/assign-a-variable-in-r-using-another-variable">here</a> and it looks like there is a way to achieve what I am trying to do, however, in the post, they assign a value to the variable. In my example, the value stored in <code>b</code> will change in every iteration of the for loop so this method will not work.</p>