mercredi 4 août 2021

R: How can I transfer values from one data frame to another data frame depending on certain circumstances?

Is there a way in R to transfer values from one data frame to a second data frame if certain conditions are met? Specifically, I am concerned with the following problem:

I have values for different people in data frame 1 (columns: name, year of birth, place of birth in ISO-3) and the polity scores for different countries in data frame 2 (columns: country in ISO-3, year, score). I would now like to add the corresponding polity scores from data frame 2 to data frame 1 as a new column depending on country and year. Can I automate this via R?

Data frame 1

Name Country of Birth Year of Birth Polity Score
Name 1 USA 2018 Score from data frame 2
Name 2 DNK 1995 Score from data frame 2

Data frame 2

Country Year Polity Score
USA 2018 10
DNK 1995 10

Aucun commentaire:

Enregistrer un commentaire