title: Create new column based on values in 2 other columns
body: <p>I am new to R and am trying to create a new column based on 2 other columns in the data frame.</p>
  
  <pre><code>UserID    Age    GradeLevel
   001       10       5
   002       10       3
   003       8        4
   004       10       7
   005       8        3
   006       8        NA
   007       10       6
   008       7        NA
   009       7        6
  </code></pre>
  
  <p>I have to create a new column "Grade". I need to first look at the age and then GradeLevel. If the assigned GradeLevel is correct then I copy the same GradeLevel to the new column. If the assigned grade level is wrong (like in obs 2, 4, 6, 8, 9) then I have to assign the users to the higher grade according to their age. </p>
  
  <p>For example a 10 years old child can be in Grade 5 or 6, but if the GradeLevel is not either 5 or 6 then assign to Grade 6 (higher grade of the 2). </p>
  
  <p>So the desired output should be like this:</p>
  
  <pre><code>UserID    Age    GradeLevel    Grade
   001       10       5            5
   002       10       3            6
   003       8        4            4
   004       10       7            6
   005       8        3            3
   006       8        NA           4
   007       10       6            6
   008       7        NA           3
   009       7        6            3
  </code></pre>
  
  <p>GradeLevel is a factor in the data, but we can covert it to character if need be. In the data I have all the GradeLevels from K thru 12.
  I am trying to use the ifelse statement, but cannot get it to work. </p>
  
  <pre><code>test$Grade.f = ifelse(test$age==10 &amp; (test$GradeLevel %in% c(5,6)), test$GradeLevel, "6")
                 ifelse(test$age==9 &amp; (test$GradeLevel %in% c(4,5)), test$GradeLevel, "5").....
  </code></pre>
  
  <p>Please I need some help with this problem.</p>