1

I have a dataframe containg persons' id's and where they come from along with other columns

id Country x
1    usa   x1
2    uk    x2
3    usa   x3
4    che   x4

and another dataframe containing country codes and their income classification

Country income
usa     upper middle
uk      high
che     low

I want to create a new column in the first dataframe that lists country classification for each person such that I have:

id Country x   CountryIncome
1    usa   x1  upper middle
2    uk    x2  high
3    usa   x3  upper middle
4    che   x4  low

Any way to do this?

balout
  • 13
  • 3

2 Answers2

1

The dplyr solution would be:

library(dplyr)
data1 <- data1 %>%
    left_join(data2, by = Country)
mikebader
  • 1,075
  • 3
  • 12
1

standard left_join from dplyr

library(dplyr)
left_join(df1, df2, by = "Country")
dy_by
  • 1,061
  • 1
  • 4
  • 13