That title might be confusing so it might be easier to show what I'm trying to do. This is what the first data frame looks like:
city | code | population |
---|---|---|
dallas | NA | 18 |
chicago | NA | 24 |
new york | NA | 13 |
dallas | NA | 90 |
And the second data frame looks like this:
city | code | feet |
---|---|---|
dallas | 1 | 1000 |
austin | 2 | 1300 |
cupertino | 3 | 908 |
chicago | 4 | 2132 |
las vegas | 5 | 1128 |
new york | 6 | 1133 |
Ultimately I want to input the code values from the second data frame into the first data frame based on the cities, so the first data frame should ultimately look like this:
city | code | population |
---|---|---|
dallas | 1 | 18 |
chicago | 4 | 24 |
new york | 6 | 13 |
How do I do that without for loops? I know how to do it with for loops, but ultimately that is really inefficient and I'm looking for an efficient way that is a line or two long. For further clarification this is not my actual data but I figured it would be the simplest way to convey my issue.