I have two datasets both with different columns however both with names. I wanted to match the names and concatenate the rows to each other
df1 <- data.frame (Name = c("Smith, Carl", "Jones, Allan", "Waterman, Josh", "Woods, Alex"),
number1 = c(1, 2, 3, 4))
df2 <- data.frame(fullname = c("Carl Smith", "Allan Jones", "Josh Waterman", "Alex Woods"),
research = c("genetics", "genetics", "mathematics", "plant"))
I would like to combine the dataset into
| Name | Number1 | Research | fullname |
|---|---|---|---|
| Smith, Carl | 1 | genetics | Carl Smith |
| Jones, Allan | 2 | genetics | Allan Jones |
| Waterman, Josh | 3 | mathematics | Josh Waterman |
| Woods, Alex | 4 | plant | Alex Woods |
I have tried merge(df1, df2, by.x = "Name", by.y = "fullname", all = TRUE)
but it doesn't match the partial names, it gives:
| Name | Number1 | Research | fullname |
|---|---|---|---|
| Smith, Carl | 1 | - | - |
| Jones, Allan | 2 | - | - |
| Waterman, Josh | 3 | - | - |
| Woods, Alex | 4 | - | - |
| - | - | genetics | Carl Smith |
| - | - | genetics | Allan Jones |
| - | - | mathematics | Josh Waterman |
| - | - | plant | Alex Woods |
merge()to matchSmith, CarltoCarl Smith? Is it truly "partial string" or do you need to matchX, YtoY Xexactly?