title: Transforming a variable using the if- else if function
body: <p>I have a data set that is that I want to calculate z scores by their year.</p>
  <p>Example:</p>
  <pre><code>  Year  Score
     1999   120
     1999   132
     1998   120
     1997   132
     2000   120
     2002   132
     1998   160
     1997   142
     ....etc
  </code></pre>
  <p>What I want is:</p>
  <pre><code>  Year  Score  Z-Score
     1999   120  1.2
     1999   132  .01
     1998   120  -.6
     1997   132  1.1
     2000   120  -.6
     2002   132  0.5
     1998   160  2.1
     1997   142  .01
  </code></pre>
  <p>I have used the following code:</p>
  <pre><code>DF$ZScore&lt;-if (DR$Year== 1997){
  ((DF$Score-220)/20)
  } else if ((DR$Year== 1998){
  ((DF$Score-222)/19)
  }...
  }else{
  ((DF$Score-219)/21)
  }
  </code></pre>
  <p>This is not working and I cannot figure out why. Any help is appreciated.</p>