I have 3 data frames. The first data frame (say df1) has multiple rows and columns. The second and third data frames (say df2 and df3) have only one row and a subset of columns from df1. The column names in df2 and df3 are same. So what I want to do is to compare each row in df1 with the single row in df2 and df3. If the value of a cell from df1 matches with the cell content of df2, replace the value of the cell in df1 with 1 and if the value of the cell from df1 matches with df3, replace the value of the cell in df1 with 2 and if the cell content of df2 doesn't match with either df2 or df3, replace the value of the cell in df1 with -. I wrote a loop to do this but it is slow. I would like to know if there is any optimized way to do this. Thank you.
Here are the example data frames and the expected output:
df1
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
q w e r t y q w e r t y
q e r t y q e r e r t y
w e r t y t q w e r w t
df2
c5 c6 c7 c8 c9 c10 c11 c12
t y q w e t w t
df3
c5 c6 c7 c8 c9 c10 c11 c12
y q q t e r t t
Expected output:
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
q w e r 1 1 1 1 1 2 2 -
q e r t 2 2 - - 1 2 2 -
w e r t 2 - 1 1 1 2 1 1