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.
The problem is, that in df1 the city name occurs more than once. So if I tried df= merge(dataset,dataset2, by.x = c("city", "Prov"), by.y = c("city", "Prov"))
I got Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column
I guess I have to programm loops but I'm not sure how.
Thanks for your help!