title: If-Then Loop in R not Recognizing Conditional Statement
body: <p>I have a data frame that looks something like the following:</p>
  
  <pre><code>X Y
  1 3
  1 7
  1 9
  2 12
  2 4
  2 8 
  3 11
  3 3
  3 5
  </code></pre>
  
  <p>I'd like to create a new variable Z that = 0.25 if X = 1, 0.75 if X = 2 and 0.95 if X = 3.</p>
  
  <p>I've tried the following code, which creates a variable Z and then loops over X, checking to see if X is a certain value, and then sets Z to the corresponding correct value. For example:</p>
  
  <pre><code>data$Z &lt;- 0
  for (i in 1:length(data$X)){
     if (data$X[i]==1) {data$Z &lt;- 0.25)
     if (data$X[i]==2) {data$Z &lt;- 0.50)
     if (data$X[i]==2) {data$Z &lt;- 0.95)
  }
  </code></pre>
  
  <p>The problem is that for some reason the conditional trigger isn't getting tripped in this code. If I just run it with the first if statement, <em>all</em> of the Z's are set to 0.25. With just the first two, they're all 0.50, etc.</p>
  
  <p>Any clue as to what's happening?</p>