The data I have look more or less like this:
data1 <- data.frame(col=c("Peter i.n.","Victor Today Morgan","Obelix","One More"))
data2 <- data.frame(num=c(123,434,545,11,22),col=c("Victor Today","Obelix Mobelix is.",
"Peter Asterix i.n.","Also","Here"))
I would like to match names across the two dataframes and get the column num
into data1.
Desired outcome:
col num
1 Peter i.n. 545
2 Victor Today Morgan 123
3 Obelix 434
I have tried this, but doesn't work as expected.
filter <- sapply(as.character(data1$col), function(x) any(grepl(x,as.character(data2$col))))
data1$num <- data2[filter,]