mercredi 31 mai 2017

Merging 2 df into one based on 2 conditions

I'm a newbe in R and have the following question:

I have two datasets (df1 and df2) that slightly differ from each other.

df1=(city=c("A", "B", "C"),Niscode = 100:110, province=c("NA", "Ant"))
df2=(city=c("A", "B", "C"), province=c("NA", "Ant"), Lokstat=1:5)

Now I want to merge them based on the following criteria because the same city can appear in differnt provinces:

If the name of the city in df1 and df2 and the province name in df1 and df2 are the same than add the Lokstat from df2 in df1.

I guess I have to programm loops but I'm not sure how.

Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire