title: R: Standardize using mean and sd functions
body: <p>I'm trying to do a simple transformation. I've used the following code and it worked fine:</p>
  
  <pre><code>data_stdz &lt;- transform(data_header, z.v1 = v1+2)
  </code></pre>
  
  <p>But, I can't get the following code to work:</p>
  
  <pre><code>data_stdz &lt;- transform(data_header, z.v1 = (v1 - mean(v1))/(2*sd(v1))
  </code></pre>
  
  <p>I've also tried to get just the mean function to work:</p>
  
  <pre><code>data_stdz &lt;- transform(data_header, z.v1 = mean(v1)
  </code></pre>
  
  <p>But, I keep getting the following error: </p>
  
  <pre><code>Error: unexpected symbol in:
  "data_std2 &lt;- transform(data_header, z.v1 = mean(v1)
  data_std2"
  </code></pre>
  
  <p>So I'm guessing it has something to do with how I am using the mean and sd function, but I have not been able to figure it out.</p>
  
  <p>Data example:</p>
  
  <pre><code>v1   v2  v3
  6.7 3.8 1.2
  6.3 3.2 1.2
  6.1 2.6 1.6
  7   2.4 1
  NA  NA  NA
  6.5 3.6 2.6
  6.1 2.4 1.6
  6   5.6 5.2
  7   2.8 1
  6.7 3.8 1.4
  5.7 4.2 2.6
  5.1 5.6 5
  NA  NA  NA
  </code></pre>