Nested IF Else in R - SAT/ACT test I have the following data set

df &lt;- data.frame(student=c(1,2,3,4,5,6,7,8,9), sat=c(365,0,545,630,385,410,0,655,0), act=c(28,20,0,0,16,17,35,29,21))

student     sat    act
    1       365    28
    2         0    20
    3       545     0
    4       630     0
    5       385    16
    6       410    17
    7         0    35
    8       655    29
    9         0    21


and I'd like to create a new field with the following conditions

If there is an SAT score > 0 use SAT score
If SAT=0, then convert the ACT to an SAT score using the rubric here. (When there was a range in the SAT score, I just used the median. 

ACT SAT
8   200
9   210
10  220
11  225
12  250
13  285
14  325
15  360
16  385
17  410
18  440
19  465
20  485
21  505
22  525
23  545
24  560
25  575
26  595
27  615
28  635
29  655
30  675
31  700
32  725
33  750
34  775
35  790
36  800


This is one heck of an ifelse statement. I've tried this: 

df$newgrade=-ifelse(ACT=8,200, ifelse (ACT=9,210, ifelse(ACT=10,220, ifelse (ACT=11,225, ACT=12,250, ifelse(ACT=13,285, ifelse (ACT=14,325, ACT=15,D, ifelse(ACT=16,C, ifelse (ACT=17,B, ACT=18,D, ifelse(ACT=19,C, ifelse (ACT=20,B, ACT=21,D, ifelse(ACT=22,C, ifelse (ACT=23,B, ACT=24,D, ifelse(ACT=25,C, ifelse (ACT=26,B, ACT=27,D, ifelse(ACT=28,C, ifelse (ACT=29,B, ACT=30,D, ifelse(ACT=31,C, ifelse (ACT=32,B, ACT=33,D, ifelse(ACT=34,C, ifelse (ACT=35,B, ACT=36,D))))))))))))))))))))


I tried to follow the example at the bottom of this page but it didn't work. 

Someone else on another board suggested: 

df$newgrade&lt;-ifelse(df$sat == 0, conversion$SAT[match(df$act, conversion$ACT)], df$sat)


but then a new issue presented itself:
If there is neither an ACT nor a SAT score. How can it put a 0 in for that group??

Thank you for any assistance you may bring.
You can indeed use the conversion table:

conversion &lt;- read.table(text = "ACT SAT
8   200
9   210
10  220
11  225
12  250
13  285
14  325
15  360
16  385
17  410
18  440
19  465
20  485
21  505
22  525
23  545
24  560
25  575
26  595
27  615
28  635
29  655
30  675
31  700
32  725
33  750
34  775
35  790
36  800", header = TRUE)


With the help of this table and mathematical/logical operators, you can create the values:

transform(df, newgrade = (sat | act) * 
            (conversion$SAT[match(df$act, conversion$ACT)] ^
               as.logical(act) * !sat) + sat)


The result:

   student sat act newgrade
1        1 365  28      365
2        2   0  20      485
3        3 545   0      545
4        4 630   0      630
5        5 385  16      385
6        6 410  17      410
7        7   0  35      790
8        8 655  29      655
9        9   0  21      505


The value in newgrade will also be 0 if both sat and act are 0.