I have a set of values in a list
list2 = c("Ford","Chrysler","Honda","Lexus","Mercedez")
and have data frame with let's say 2 columns and am looking to fill Match_Flag
column based on if the value exists in list2
.
Make Match_Flag
Ford
Mercedez
Chrysler
Here's my current work:
for (i in 1:length(df$Make)){
if(df$Make[[i]] %in% list2){
df$Match_Flag == 1
}
else {
df$Match_Flag == 0
}
}
This assignment of 1 and if condition doesn't seem to work and all values are assigned 0s instead. This is slightly different from the other question linked as this involves comparing a list with another list versus checking for an element in the list. Thanks.