I have a dataframe that looks like:
animal_id trait_id sire_id dam_id
1 25.05 0 0
2 -46.3 1 2
3 41.6 1 2
4 -42.76 3 4
5 -10.99 3 4
6 -49.81 5 4
I want to create another variable that contains the estimate of "trait_id" for each "sire_id" and "dam_id".
All sires (sire_id) and dams (dam_id) are also present in the animal_id column. So what I want to do is to look for their measurement in the trait_id and repeat this variable in the new variable.
The outcome that I want is:
animal_id trait_id sire_id trait_sire dam_id trait_dam
1 25.05 0 NA 0 NA
2 -46.3 1 25.05 2 -46.3
3 41.6 1 25.05 2 -46.3
4 -42.76 3 41.6 4 -42.76
5 -10.99 3 41.6 4 -42.76
6 -49.81 5 -10.99 4 -42.76
Any suggestion would be greatly appreciated.