I have the following data setdf <- 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    21and I'd like to create a new field with the following conditionsIf there is an SAT score > 0 use SAT scoreIf 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 SAT8   2009   21010  22011  22512  25013  28514  32515  36016  38517  41018  44019  46520  48521  50522  52523  54524  56025  57526  59527  61528  63529  65530  67531  70032  72533  75034  77535  79036  800This 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<-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.
Nested IF Else in R - SAT/ACT test
r
You can indeed use the conversion table:conversion <- read.table(text = ACT SAT8   2009   21010  22011  22512  25013  28514  32515  36016  38517  41018  44019  46520  48521  50522  52523  54524  56025  57526  59527  61528  63529  65530  67531  70032  72533  75034  77535  79036  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 newgrade1        1 365  28      3652        2   0  20      4853        3 545   0      5454        4 630   0      6305        5 385  16      3856        6 410  17      4107        7   0  35      7908        8 655  29      6559        9   0  21      505The value in newgrade will also be 0 if both sat and act are 0.