new to R.
Let's suppose I have two different data frames, both data frames contain the same column, ZIP_CODE. How can I add data from one data frame to the other if the ZIP_CODE matches on both data frames?
Let me provide more specifics to my particular problem in hopes of explaining it more clearly:
I have two different data frames, lets call them df_airbnb and df_zipcodes
A condensed version of df_airbnb looks something like:
| listingID | ZIP_CODE | PRICE |
|---|---|---|
| 123656 | 78345 | 140 |
| 234567 | 78645 | 69 |
Here the unique identifier is the listingsID column, and there is more than one record per ZIP_CODE. This data frame contains about 20,000 rows.
A condensed version of df_zipcodes looks something like:
| ZIP_CODE | $/SQFT |
|---|---|
| 78635 | 250 |
| 12356 | 120 |
Here the unique identifier is the ZIP_CODE column. This data frame only contains about 150 rows, one for each ZIP_CODE in a particular metropolitan area.
So what I want to do is go through every row of df_airbnb, search for the matching ZIP_CODE in the df_zipcodes and then add the $/SQFT data from the df_zipcodes to df_airbnb. As a side note, there is a possibility that a ZIP_CODE in df_airbnb might not be contained in df_zipcodes potentially creating a no match found situation.
Let me know if more context is needed.
Any help would be greatly appreciated!
I am not sure where to begin. I though about cbind but this is only if the number of rows in both data frames were there same.