Create a new data frame column based on another column
===


I have a data frame with two columns, and want to create a third column which will essentially be a boolean for whether or not column two contain a certain set of specified values. 


    f <- data.frame(name=c("John", "Sara", "David", "Chad"),
                     car=c("Honda|Ford", "BMW", "Toyota|Chevy|Ford", 
                     "Toyota|Chevy|Ford|Honda"))

The first thing I did was remove the | from each string in the second column, and placed those valued in a third column

    library(stringr)
    g = str_replace_all(f$car, "[^[:alnum:]]", " ")
    f$make = c(g)
    f
What I want to do now if create another column, which will be a boolean, 1 if make contains a common car, and 0 if it contains a not common car. 

    common = c("Honda", "Ford", "Toyota", "Chevy")
    not_common = c("BMW", "Lexus", "Acura")

I've tried a few things, including the stringr package and ifelse to produce the following output.

       name                     car                    make       common   
    1  John              Honda|Ford              Honda Ford           1
    2  Sara                     BMW                     BMW           0
    3 David       Toyota|Chevy|Ford       Toyota Chevy Ford           1
    4  Chad Toyota|Chevy|Ford|Honda Toyota Chevy Ford Honda           1

Since it's possible to have both a common and uncommon car as an entry, the uncommon make should override the common make and that row should take the value 0 in the common column. So if an entry had both BMW and Ford, that entry should take a 0 in the common column.

Can anyone help with this task. 

Oh, and here's what I tried with the stringr package, but it doesn't work.

    common = c("Honda", "Ford", "Toyota", "Chevy")
    not_common = c("BMW", "Lexus", "Acura")
    common_match <- str_c(common)
    not_match <- str_c(not_common)
    
    main <- function(df) {
      f$new_make <- str_detect(f$make, common_match)
      df
    }
    
    main(f)


Thanks!

