title: R lapply: check if data frame contains a column. If not, create this column
body: <p>I have a list of dataframes. </p>
  
  <p>I would like to check every column name of the dataframes. If the column name is missing, I want to create this column to the dataframe, and complete with NA values.</p>
  
  <p>Dummy data:</p>
  
  <pre><code>d1 &lt;- data.frame(a=1:2, b=2:3, c=4:5)
  d2 &lt;- data.frame(a=1:2, b=2:3)
  
  l&lt;-list(d1, d2)
  
  # Check the columns names of the dataframes 
  # If column is missing, add new column, add NA as values 
  lapply(l, function(x) if(!("c" %in% colnames(x))) 
               {
                c&lt;-rep(NA, nrow(x))
                cbind(x, c) # does not work!
                })
  </code></pre>
  
  <p><strong>What I get:</strong></p>
  
  <pre><code>[[1]]
  NULL
  
  [[2]]
    a b  c
  1 1 2 NA
  2 2 3 NA
  </code></pre>
  
  <p><strong>What I want instead:</strong></p>
  
  <pre><code>[[1]]
    a b c
  1 1 2 4
  2 2 3 5
  
  [[2]]
    a b c
  1 1 2 NA
  2 2 3 NA
  </code></pre>
  
  <p>Thanks for your help!</p>