title: R - Obtain Column Names for Each Dataframe in a List based on a Parameter
body: <p>I have a list of dataframes that I have divided in order to do individual statistics on. The dataframes have names to columns that I want to extract based on a value in a row. Take these dataframes for example compiled in <code>df_list</code>:</p>
  <pre><code>$df1
    aa bb cc
  a  9  9  2
  b  9  9  6
  c  2 10  5
  d  2  9  6
  e  3  4  7
  
  $df2
    aa bb cc
  a  2  4  3
  b  2  8  2
  c  6  4  3
  d  9  5  8
  e  1  5  4
  
  $df3
    aa bb cc
  a  1  8  2
  b  1  8  9
  c  4  1  2
  d  9  9  8
  e  9  7  3
  </code></pre>
  <p>I wanted to obtain the names  of columns if row e is greater than 5. So I would get an output something like this either in the same list or a brand new list:</p>
  <pre><code>$df1
    [1] &quot;cc&quot; 
  
  $df2
    NULL  #or integer(0), I'm not quite sure what I would see here
  
  $df3
    [1] &quot;aa&quot;    &quot;bb&quot;
  </code></pre>
  <p>I've come up with this code to get the names of all columns:</p>
  <pre><code>names_list &lt;- lapply(df_list, function(x) colnames(x))
  
  $df1
  [1] &quot;aa&quot; &quot;bb&quot; &quot;cc&quot;
  
  $df2
  [1] &quot;aa&quot; &quot;bb&quot; &quot;cc&quot;
  
  $df3
  [1] &quot;aa&quot; &quot;bb&quot; &quot;cc&quot;
  </code></pre>
  <p>And this is the line of code for columns greater than 5:</p>
  <pre><code>num_list &lt;- lapply(df_list, function(x) which(x[c(&quot;e&quot;),] &gt; 5))
  
  $df1
  [1] 3
  
  $df2
  integer(0)
  
  $df3
  [1] 1 2
  </code></pre>
  <p>While the last two results are promising, I can't seem to connect the two ideas together to get the desired output. Nesting them gives me countless errors I can't identify. Is there a feasible way to do this? Is there a more efficient way?</p>