vendredi 6 avril 2018

ifelse and elseif statements in R

I'm much more familiar with if else statements in SAS. However, I'm a little confused with how R handles these statements. I'm having trouble when it comes down to ifelse statements that have more than one condition.

Each of these variables has around 1000 values, so I can't use a simple if else in R because I get this error "the condition has length > 1 and only the first element will be used"

This is what I'm trying to code in R (this is it in SAS right now)

if F_low ne . then do; 
    low = F_low; 
    high = F_high;  
    end;
else if UF_low ne . then do; 
    low = UF_low; 
    high = UF_high; 
    end;
else if T_low ne . then do; 
    low = T_low; 
    high = T_high; 
    end;
else if UNK_low ne . then do;
    low = UNK_low; 
    high = UNK_high;  
    end;
run;

Thank you!!

Aucun commentaire:

Enregistrer un commentaire