Update column values from another data frame if the first 4 strings match

I have 2 data frames df1 and df2 and I want to update df1$Country.Names by df2$Area if the first 4 strings of df1$Country.Names matches with df2$Area, if not they are deleted from df1.

df1$Country.Names <- c("Bahamas the," , "United states", "France","Asia")
df2$Area<- c("Bahamas", "United states of america","United states of america", "France")

The output need should be like this for df1

|Country.Names | 
| -------- | 
| Bahamas   | 
| United states of america | 
| France|

Given that the only members that the two lists have in common is France, so how are we to understand your requirements in light of that ?

You can see that "Bahamas the," is updated to "Bahamas" and "United states" is updated to "United states of america", and "France" still look the same but it may or may not need to be changed as for "Asia" it's gone.

I think you need to use stringdist package

How am going to use it ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.