I have df1
df1 <- data.frame(states = c("wash", "mont", "oreg", "cali", "michi"), key1 = c(1,3,5,7,9), key2 = c(2,4,6,8,10))
which looks like this (key1 and key2 are arrays of keys):
states key1 key2
1 wash 1 2
2 mont 3 4
3 oreg 5 6
4 cali 7 8
5 michi 9 10
df2 has more information
df2 <- data.frame(sample = c(9,8,5,4,1), value = c("steel", "gold", "blue", "grey", "green"))
which is as follows:
sample value
1 9 steel
2 8 gold
3 5 blue
4 4 grey
5 1 green
samples in df2 must be mapped to EITHER key1 or key2 in df1 to make df3
states key1 key2 sample value
1 wash 1 2 1 green
2 mont 3 4 4 grey
3 oreg 5 6 5 blue
4 cali 7 8 8 gold
5 michi 9 10 9 steel
I can just delete the sample column ... no problem. How to extend df2 to df3 if the value for the pattern can be in key1 or key2?
Thank!