I'm working on a dataset and I need to find all even and odd records of 4 variables. I have SAS code where this has been done, but the if else statements seem more straightforward to me in SAS than in R. I'm looking for outcome where the variable even is coded as one if the records are even and 0 if they are odd. The SAS code is:
data even;
set Validation;
if mod(MNTHLY_ED_VISITS,2)=0 or mod(FIRE_RLTD_ED_VISITS,2)=0 or mod(NON_FIRE_RLTD_ED_VISITS,2)=0 or mod(UNKN_ED_VISITS,2)=0 then even=1;
else even=0;
run;
proc freq data=even;
tables even;
run;
In R I've been trying nested ifelse statements thinking this would work. The code is:
even <- ifelse(mod(ED_CO$MNTHLY_ED_VISITS,2)==0, ifelse(mod(ED_CO$FIRE_RLTD_ED_VISITS,2)==0, ifelse(mod(ED_CO$NON_FIRE_RLTD_ED_VISITS,2)==0, ifelse(mod(ED_CO$UNKN_ED_VISITS)==0))),1,0)
This gave me the error "Error in ifelse(mod(ED_CO$MNTHLY_ED_VISITS,2)==0, ifelse(mod(ED_CO$FIRE_RLTD_ED_VISITS, : unused arguement (0).
Any help with this would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire