I would like to add a column to my data frame based upon the values in other columns.
Here is an extract of the data.
On each row if any of the 4 TOPER columns have any of the following values (92514, 92515, 92508, 92510, 92511 or 92512( i want the S_Flag
column to be equal to 1, If not the S_Flag
value should be 0.
Have highlighted the data where this true (case nos 2, 4, 6 and 8) - therefore S_Flag
should be made 1.
Have tried using a ifelse
inside a mutate
function. Just not sure how to identify looking across all 4 TOPER columns within the ifelse
function???
Have tried
tt <- mutate(rr, S_Flag = ifelse( any(vars(everything()) %in% toper_vec), 1,0))
where rr
is the original data frame and toper_vec
is a vector containing the 6 TOPER column values.
Hope that makes sense. By the way i am in early stages of learning R. Thank you for any assistance.