title: R special if- statement over column names
body: <p>I have a data frame and I want to add the units (µg,g,...)to the values of the columnnames. My data is called BLS_datatable. I have added the units seperately with the following code. I know that is a bit redundant, but it works. The value here is KiloJoule.</p>
  
  <pre><code>colnames(BLS_datatable) &lt;- gsub(colnames(BLS_datatable), pattern = 'KiloJoule', replacement = 'KiloJoule[kj]')
  </code></pre>
  
  <p>mg is the most common unit in my data frame that consists of more than 100 columns. I want to do a "if statement" for adding the unit mg to the suitable values. Unfortunately, this is not working:</p>
  
  <pre><code>if("[" %in% colnames(BLS_datatable)){
    print(colnames(BLS_datatable))
  } else {
    print(colnames(c(BLS_datatable),"[mg]"))
  }
  </code></pre>
  
  <p>What is wrong here?
  Thank you for helping me
  ,Cheers</p>