title: How to add a new column in data frame using calculation in R?
body: <p>I want to add a new column with calculation. In the below data frame,</p>
  <pre><code>Env&lt;- c(&quot;High_inoc&quot;,&quot;High_NO_inoc&quot;,&quot;Low_inoc&quot;, &quot;Low_NO_inoc&quot;)
  CV1&lt;- c(30,150,20,100)
  CV2&lt;- c(74,99,49,73)
  CV3&lt;- c(78,106,56,69)
  CV4&lt;- c(86,92,66,70)
  CV5&lt;- c(74,98,57,79)
  
  Data&lt;-data.frame(Env,CV1,CV2,CV3,CV4,CV5)
  
  Data$Mean &lt;- rowMeans(Data %&gt;% select(-Env))
  Data &lt;- rbind(Data, c(&quot;Mean&quot;, colMeans(Data %&gt;% select(-Env))))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/PhGn5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PhGn5.jpg" alt="enter image description here" /></a></p>
  <p>I'd like to add a new column names 'Env_index' with calculation {each value of 'mean' column - overall mean (<strong>76.3</strong>) such as 68.4 - <strong>76.3</strong> , 109- <strong>76.3</strong> ,... 78.2 - <strong>76.3</strong></p>
  <p>So, I did like this and obtained what I want.</p>
  <pre><code>Data$Env_index &lt;- c(68.4-76.3,109-76.3,49.6-76.3,78.2-76.3, 76.3-76.3)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/VMvea.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VMvea.png" alt="enter image description here" /></a></p>
  <p>But, I want to directly calculate using code, so if I code like this,</p>
  <pre><code>Data$Env_index &lt;- with (data, data$Mean - 76.3)
  </code></pre>
  <p>It generates error. Could you let me know how to calculate?</p>
  <p>Thanks,</p>