title: R subsetting a data frame into multiple data frames based on multiple column values
body: <p>I am trying to subset a data frame, where I get multiple data frames based on multiple column values. Here is my example</p>
  
  <pre><code>&gt;df
    v1   v2   v3   v4   v5
     A    Z    1    10   12
     D    Y    10   12    8
     E    X    2    12   15
     A    Z    1    10   12
     E    X    2    14   16
  </code></pre>
  
  <p>The expected output is something like this where I am splitting this data frame into multiple data frames based on column <code>v1</code> and <code>v2</code></p>
  
  <pre><code>&gt;df1
   v3   v4   v5
    1   10   12
    1   10   12
  &gt;df2
   v3   v4   v5
   10   12    8
  &gt;df3
   v3   v4   v5
   2    12   15
   2    14   16
  </code></pre>
  
  <p>I have written a code which is working right now but don't think that's the best way to do it. There must be a better way to do it. Assuming <code>tab</code> is the data.frame having the initial data. Here is my code: </p>
  
  <pre><code>v1Factors&lt;-levels(factor(tab$v1))
  v2Factors&lt;-levels(factor(tab$v2))
  
  for(i in 1:length(v1Factors)){
    for(j in 1:length(v2Factors)){
      subsetTab&lt;-subset(tab, v1==v1Factors[i] &amp; v2==v2Factors[j], select=c("v3", "v4", "v5"))
      print(subsetTab)
    }
  }
  </code></pre>
  
  <p>Can someone suggest a better method to do the above?</p>