title: Subtracting two columns to give a new column in R
body: <p>Hello I´am trying to subtract the column <code>B</code> from column <code>A</code> in a <code>dat</code> matrix to create a <code>C</code> column  (<code>A</code> - <code>B</code>):</p>
  
  <p>My input:</p>
  
  <pre><code>A  B
  1  2
  2  2
  3  2
  4  2
  </code></pre>
  
  <p>My expected output:</p>
  
  <pre><code>A  B  C
  1  2 -1
  2  2  0
  3  2  1
  4  2  2
  </code></pre>
  
  <p>I have tried: <code>dat$C &lt;- (dat$A - dat$B)</code>, but I get a: <code>## $ operator is invalid for atomic vectors</code>error</p>
  
  <p>Cheers.</p>