title: How to scale a variable by group
body: <p>I would really appreciate your help in this question.
  I have the following dataset and I would like to create a new variable which would contain the standardized values (z distribution) per level of a given factor variable. </p>
  
  <pre><code>x &lt;- data.frame(gender = c("boy","boy","boy","girl","girl","girl"),
                  values=c(1,2,3,6,7,8)) 
  x
  
     gender values
  1    boy      1
  2    boy      2  
  3    boy      3
  4   girl      6
  5   girl      7
  6   girl      8
  </code></pre>
  
  <p>My aim is to create one new variable which will contain the z-values calculated separately for each factor level (for boys and for girls). </p>
  
  <p>And another question. I mainly would like to create a variable with the z-values. Would it be similar if I would like to apply another function and for example calculate distribution in quantiles per factor level?</p>
  
  <p>Thank you for your help!</p>