title: How to create a loop inside a loop in R
body: <p>I am new to R and I need some help in relation loops. I need to produce a huge amount to tables from one data set and I think that a loop inside a loop will solve the problem, but I am having problems getting the right result.</p>
  
  <p>Lets say I have the following data set:</p>
  
  <pre><code>var1 &lt;- c("A","A","A","A","B","B","B","B")
  var2 &lt;- c(1,2,1,2,1,2,1,2)
  df &lt;- data.frame(var1,var2)
  </code></pre>
  
  <p>And I want to extract the data in 4 tables:</p>
  
  <ul>
  <li>Result of "A" &amp; 1</li>
  <li>Result of "A" &amp; 2</li>
  <li>Result of "B" &amp; 1</li>
  <li>Result of "B" &amp; 2</li>
  </ul>
  
  <p>I have this loop, but I cannot get the 4 tables. Can anyone help!</p>
  
  <pre><code>for (i in df$var1) {
  
      dummy&lt;- df%&gt;%filter(var1 == i)
  
      for (j in dummy$var2) {
  
         nTab &lt;- paste0("tab_", j, sep ="")
         assign(nTab, dummy%&gt;%filter (var2 == j))
  
     }
  }
  </code></pre>