Hello! Below is my exmample. "myref" is my reference data frame with columns a and b. "temp" is my data with column c analogous to column a in "myref". I am trying to create a new variable b - in "temp" - that matches values from b in "myref" to values in c. If you look at the resulting data frame (temp - at the bottom), you'll notice that rows 19-24 are incorrect. How could one fix it? Thanks a lot!
# my reference data frame: a=c("ba ba","ca ca","da da", "lake lake, a", "lake lake, b","lake of","lama ca, a","lama ca, b","ma ma") b=c("ba ba","ca ca","OTHER", "lake lake, a", "lake lake, b","lake of","lama ca, a","lama ca, b","OTHER") myref<-data.frame(a=a, b=b) (myref) # my data: c<-c(rep("ba ba",3),rep("ca ca",3),rep("da da",3),rep("lake lake, a",3), rep("lake lake, b",3),rep("lake of",3),rep("lama ca, a",3),rep("lama ca ,b",3),rep("ma ma",3)) temp<-data.frame(c=c) (temp) ### Matching: temp$b<-myref[temp$c,"b"] (temp) -- Dimitri Liakhovitski Ninah Consulting www.ninah.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.