I have a dataframe as follows:
df <- data.frame(matrix(NA, nrow = 5, ncol = 1))
colnames(df) <- "father"
df$father <- c("A", "B", "B","C","D")
df$id <- c("C", "E","F","G","H")
df$pop <- c("ref","ref","ref","val","val")
Which gives:
father id pop
1 A C ref
2 B E ref
3 B F ref
4 C G val
5 D H val
Then if "id" appears in "father", the value of the pop should be the one that appears in the row of the father. For example in this example "C" appears both in "father" and in "id", in father C the pop is val, then, I want the pop of C as id to be val as follows:
father id pop
1 A C val
2 B E ref
3 B F ref
4 C G val
5 D H val
Any ideas?