title: find whether a column exists in R data frame and if not then create it
body: <p>I have following dataframe in R</p>
  
  <pre><code> no     qc6    qc5    qc3     itv6   itv5    itv3
  123      12    12     14      8      9       9
  </code></pre>
  
  <p>Now, I want to check whether following columns exist in a dataframe or not and if not then create a new column with 0 value in it.</p>
  
  <pre><code> qc1,qc2,itv1,itv2
  </code></pre>
  
  <p>I can do it with if loop in R</p>
  
  <pre><code> if(!"qc1" %in% colnames(df))
   {
     df$qc1 &lt;- 0
   }
  </code></pre>
  
  <p>But, then I will have to write loops for every variable to create. Is there any faster way of doing it ?</p>