Multiple actions from multiple if / else if statements - R
<p>I'm new to R and am experiencing a problem properly populating a column of data within a data frame.  I'm populating two columns (P_Score and P_Class) based on another column (P_Value) using a series of if / else if statements.</p>

<pre><code>i&lt;- 0
nr&lt;- nrow(myData)
while(i&lt;nr){
  i&lt;-1+i
  if(toString(myData$P_Value[i])=="NA"){ myData$P_Score[i] &lt;- myData$P_Value[i]
  } else if (as.numeric(toString(myData$P_Value[i]))&lt;5){
      myData$P_Score[i] &lt;- 1; myData$P_Class[i] &lt;- "Minimal Depression";
  } else if (as.numeric(toString(myData$P_Value[i]))&lt;10){
      myData$P_Score[i] &lt;- 2; myData$P_Class[i] &lt;- "Mild Depression";
  } else if (as.numeric(toString(myData$P_Value[i]))&lt;15){
      myData$P_Score[i] &lt;- 3; myData$P_Class[i] &lt;- "Moderate Depression";
  } else if (as.numeric(toString(myData$P_Value[i]))&lt;20){
      myData$P_Score[i] &lt;- 4; myData$P_Class[i] &lt;- "Moderate-Severe Depression";
  } else 
      myData$P_Score[i] &lt;- 5; myData$P_Class[i] &lt;- "Severe Depression";
}
</code></pre>

<p>However, this is not giving me my desired result, and instead I wind up with this:</p>

<pre><code>P_Value  P_Score    P_Class
4        1          Severe Depression
25       5          Severe Depression
8        2          Severe Depression
13       3          Severe Depression
17       4          Severe Depression
1        1          Severe Depression
12       3          Severe Depression
</code></pre>

<p>So the P_Score is populating just fine, but the P_Class is always defaulting to "Severe Depression".   I must be having some issue executing multiple statements based off of 1 if condition, but I can't figure out what I'm doing wrong.  I have read elsewhere as long as you put semicolons after the statements both should work, but that's clearly not working.  </p>

<p>I have also tried spacing out the commands like this:</p>

<pre><code>} else if (as.numeric(toString(myData$P_Value[i]))&lt;5){
  myData$P_Score[i] &lt;- 1
  myData$P_Class[i] &lt;- "Minimal Depression"
</code></pre>

<p>But that does not seem to work either.  Please help! </p>