I created a new column with values from another data frame. The problem is that there are empty rows in both data frames. So I assigned incorrectly the names first empty row with the second table for empty rows in first table.
My code:
df1 <- data.frame(age=c(23," ",55,34,45),
name=c("A","S","P","J","M"))
df2 <- data.frame(age=c(" ",43,55,34,45),
name=c("Alex","Silvia","Peter","Jack","Michael"))
df1$names2 <- df2$name[match(df1$age, df2$age)]
> df1
age name names2
1 23 A <NA>
2 S Alex
3 55 P Peter
4 34 J Jack
5 45 M Michael
First result record is ok, but the second shows incorrect information.