title: In R, how do I recursively store columns of a data frame as a data frame?
body: <p>In R, I want to recursively go through the columns of a data frame and select each column to make a boxplot against a given column.
  Here is my attempt</p>
  <pre><code>#define dataframe
  library(ggplot2)
  df &lt;- mpg
  
  #get unique column names
  IDs &lt;- unique( colnames(df) )
  for (name in IDs){ 
    #goal: store column as a data frame, actual: store column as a list 
    temp &lt;- df[name]
    #plot column of data vs cty miles per gallon
    boxplot(temp ~ df$cty)
  }
  </code></pre>
  <p>I get this error (because it needs to be a dataframe not a list):</p>
  <blockquote>
  <p>Error in stats::model.frame.default(formula = temp ~ df$cty) :<br />
  invalid type (list) for variable 'temp'</p>
  </blockquote>