How to check whether value in dataframe A appears in dataframe B and return a binary value if true?

Viewed 31

I need some dplyr merging 101 help, please. I have merged my Main List of schools and their attributes (see Table A. below) with the State Database (Table B.). Some of the school names are written differently in my database and therefore while the merge works for many schools, the attributes (like 'Type' in Table A) cannot be found in instances where the name is incorrect in my A. Main List. The solution that I have thought of is to create a variable within A. called, "Found in state database" and assign it binary values accordingly. If I get a "0", then I know to go in manually and clean up the school name.

How can I reference both 2 dfs at once and create the variable that I have described? Or is there something easier that I haven't thought of. Thanks in advance.

A. Main List

School Type Found in state database
Apple ES Charter 0
Bolton High District 1
Bruce Elementary District 0

B. State Database

School Exceeded Expectations
Apple Elementary 23%
Bolton High 82%
Bruce ES 44%
1 Answers

Why not find which values are not found in the other with a logical operation on unique values:

 vals <- unique( Main_list$School )
 vals[ ! vals %in% unique(State_Database$School) ] #returns vector of school names

There are also approximate merges. Install the fuzzyjoin package.

Related