title: How can I run a for loop that subsets multiple lists all of which contain dataframes
body: <p>I have 5 lists called &quot;nightclub&quot;, &quot;hospital&quot;, &quot;bar&quot;, &quot;attraction&quot;, &quot;social_facility&quot; all of which contain a data frame called osm_points. I want to create a new list with 5 dataframes with the names of the original dataframes that only contain 3 vectors &quot;osm_id&quot;,&quot;name&quot;,&quot;addr.postcode&quot; with no NA values for the vector &quot;addr.postcode&quot;. Below is my attempted code, I do not know another way to subset lists without $ (which gives me an error for having an atomic vector), or without the square brackets. Let know if you guys have some advice.</p>
  <pre><code>vectors &lt;- c(&quot;osm_id&quot;,&quot;name&quot;,&quot;addr.postcode&quot;)
  features &lt;- c(&quot;nightclub&quot;, &quot;hospital&quot;, &quot;bar&quot;, &quot;attraction&quot;, &quot;social_facility&quot;)
  datasets &lt;- list()
  n &lt;- 0
  
  
  for (i in features){
    n &lt;- n + 1
    datasets[[n]] &lt;- paste(i)[[&quot;osm_points&quot;]][!is.na(paste(i)[[&quot;osm_points&quot;]][[&quot;addr.postcode&quot;]]), variables]
  }
  </code></pre>
  <p>I managed to do this operation without a for loop (below), but I want to be able to code better and do it all in one operation. Thanks so much for your help.</p>
  <pre><code>nightclub1 &lt;- nightclub$osm_points[!is.na(nightclub$osm_points$addr.postcode), variables]
  </code></pre>
  <p>Thanks !!</p>