Perhaps this complementary example of "match" would be helpful.
Having two datasets:
first_dataset <- data.frame(name = c("John", "Luke", "Simon", "Gregory", "Mary"),
role = c("Audit", "HR", "Accountant", "Mechanic", "Engineer"))
second_dataset <- data.frame(name = c("Mary", "Gregory", "Luke", "Simon"))
If the name column contains only unique across collection values (across whole collection) then you can access row in other dataset by value of index returned by match
name_mapping <- match(second_dataset$name, first_dataset$name)
match returns proper row indexes of names in first_dataset from given names from second: 5 4 2 1
example here - accesing roles from first dataset by row index (by given name value)
for(i in 1:length(name_mapping)) {
role <- as.character(first_dataset$role[name_mapping[i]])
second_dataset$role[i] = role
}
===
second dataset with new column:
name role
1 Mary Engineer
2 Gregory Mechanic
3 Luke Supervisor
4 Simon Accountant