I have two different data frames 'df1' and 'df2' with six matching column names. I want to scan df2 for rows that match exactly in df1, and if they do enter a 1 in the 'detect' column of df1 and if not enter a 0 in that column. Currently all values of 'detect' in df1 are 0's, but I want those to change to 1 when there's an exact match between the two data frames. It would look like this:
df1
| site | ddate | ssegment | spp | vtype | tperiod | detect |
|---|---|---|---|---|---|---|
| BMA | 6/1/2021 | 1 | AMRO | Song | 1 | 0 |
| BMC | 6/15/2021 | 1 | WISN | Drum | 1 | 0 |
| BMA | 6/15/2021 | 1 | NOFL | Song | 2 | 0 |
| BMC | 6/29/2021 | 2 | AMRO | Call | 1 | 0 |
| BMA | 6/29/2021 | 2 | WISN | Call | 2 | 0 |
df2
| site | ddate | ssegment | spp | vtype | tperiod |
|---|---|---|---|---|---|
| BMA | 6/1/2021 | 1 | AMRO | Call | 1 |
| BMC | 6/15/2021 | 1 | WISN | Drum | 1 |
| BMA | 6/15/2021 | 1 | NOFL | Song | 2 |
| BMC | 6/29/2021 | 2 | AMRO | Drum | 1 |
| BMA | 6/29/2021 | 2 | WISN | Call | 2 |
After scanning these, df1 would now look like:
df1
| site | ddate | ssegment | spp | vtype | tperiod | detect |
|---|---|---|---|---|---|---|
| BMA | 6/1/2021 | 1 | AMRO | Song | 1 | 0 |
| BMC | 6/15/2021 | 1 | WISN | Drum | 1 | 1 |
| BMA | 6/15/2021 | 1 | NOFL | Song | 2 | 1 |
| BMC | 6/29/2021 | 2 | AMRO | Call | 1 | 0 |
| BMA | 6/29/2021 | 2 | WISN | Call | 2 | 1 |
I was thinking that R base function 'merge' might be useful, but I can't quite figure it out. Thank you for your help!