title: Subset list based on a condition in R
body: <p>For a sample dataframe:</p>
  
  <pre><code>df &lt;- structure(list(area = structure(c(1L, 4L, 3L, 8L, 5L, 7L, 6L, 
  2L), .Label = c("DE1", "DE3", "DE4", "DE5", "DE9", "DEA", "DEB", 
  "DEC"), class = "factor"), to.delete = c(1L, 0L, 1L, 0L, 1L, 
  1L, 1L, 0L)), .Names = c("area", "to.delete"), class = "data.frame", row.names = c(NA, 
  -8L))
  </code></pre>
  
  <p>I want to create a list of the areas which have a '1' in the 'to'delete' column.  I know how to subset the 1s out of this dataframe, however I want the list of areas as eventually I will use this list to extract these areas from the main master data file (df2, listed below).</p>
  
  <pre><code>df2 &lt;- structure(list(id = 1:24, area = structure(c(1L, 1L, 4L, 4L, 
  4L, 3L, 3L, 3L, 3L, 3L, 8L, 8L, 8L, 8L, 5L, 7L, 7L, 7L, 6L, 6L, 
  2L, 2L, 2L, 2L), .Label = c("DE1", "DE3", "DE4", "DE5", "DE9", 
  "DEA", "DEB", "DEC"), class = "factor")), .Names = c("id", "area"
  ), class = "data.frame", row.names = c(NA, -24L))
  </code></pre>
  
  <p>I prefer to do this in two steps, so I can easily see which areas I have deleted (thanks to answers below for suggestions of using list).</p>
  
  <pre><code>a &lt;- list(df$area[df$to.delete == 1])
  df2.subset &lt;- df2[df2$area %in% a,]
  </code></pre>
  
  <p>This however doesn't seem to work at the moment, so if anyone has any ideas, then that would be great.</p>
  
  <p>df2 should then be left with only areas DE5, DEC and DE3.</p>
  
  <p>Many thanks.</p>