I'm recoding numerous SAS applications into R where "If Then Do" logic appears frequently.
Example SAS Code:
if (missing(minority) = 0 AND missing(amin =0 ) then do;
if ( amin = 1 OR hawaii = 1 ) then
other = 1 ;
else other = 0 ;
The R code below works:
recode <- joined_df %>%
mutate(flag_one = case_when(
is.na(minority) & is.na(amin) ~ 9),
other = case_when(
flag_one== 9 & (amin == 1 | hawaii_ == 1) ~ 1, TRUE ~ 0 )
I was wondering if there is a more elegant way code to do this in tidyverse so I don't create and then drop temporary flags.