title: How to refer to other things in R loop
body: <p>Say that I have this data:</p>
  
  <pre><code>library(dplyr)
  data &lt;- data.frame(num=c(1:6), val=c('1998-99', '1999-00', '2000-01', '2001-02', '2002-03', '2003-04'))
  </code></pre>
  
  <p>I then have several things that would be useful to figures out, mainly about how the values in a loop refer to other values and how to automate this process.</p>
  
  <p>It would be best to put this in a loop. How to do so with data frame names? In other words, how to refer to the name of a data.frame in a loop?</p>
  
  <pre><code>data03 &lt;- filter(data, num&lt;=1)
  data04 &lt;- filter(data, num&lt;=2)
  data05 &lt;- filter(data, num&lt;=3)
  data06 &lt;- filter(data, num&lt;=4)
  data07 &lt;- filter(data, num&lt;=5)
  data08 &lt;- filter(data, num&lt;=6)
  </code></pre>
  
  <p>Then, how to make this loop work and simplified?</p>
  
  <pre><code>for (i in c(03, 04, 05, 06, 07, 08)) {
      #I want to print the number corresponding to i
      if(i=="03") print(1)
      if(i=="04") print(2)
      if(i=="05") print(3)
      if(i=="06") print(4)
      if(i=="07") print(5)
      if(i=="08") print(6)
      #I want to get the value corresponding to i for the plot title
      if(i=="03") title="1998-99"
      if(i=="04") title="1999-00"
      if(i=="05") title="2000-01"
      if(i=="06") title="2001-02"
      if(i=="07") title="2002-03"
      if(i=="08") title="2003-04"
      #I want to open the data frame, data+i
      df &lt;- paste(data,i) 
      #I want to plot, using the title saved above
      plot(df$num, main=title)
  }
  </code></pre>