I have a dataframe (relationship) in R containing relationships between animals:
animal1 | animal2 | relationship
dog cat friendly
cat dog amicable
pig goose mean
I have another dataframe (animal) containing info about each animal:
id | animal | count
1 dog 2
2 cat 5
3 pig 1
4 goose 2
I want to replace the animals in the first dataframe with the values of their IDs in the second data frame, i.e.
animal1 | animal2 | relationship
1 | 2 | friendly
2 | 1 | amicable
3 | 4 | mean
How do I do this? So far, I am able to use grepl to do this for an individual item, i.e.
which(grepl(relationship$animal1[3],animal$id)) >>>> 2
How can I apply this generally over the whole relationship data frame and replace the animal1/animal2 columns with the result?