My two (input) data.frames look like this:
df1
Group Name Vote
AB a Sentence1
AB b Sentence2
AB c Sentence3
XY d Sentence4
XY e Sentence5
XY f Sentence6
ZW a Sentence7
ZW b Sentence8
ZW c Sentence9
df2
AB XY ZW
a d a
b e b
c f c
I need to replace df2 respective contents with df1$Vote. Notice that both group AB and ZW share the same Name elements - so it important to also check that both (column) names & content match between tables.
Like this:
Resulting df3:
AB XY ZW
Sentence1 Sentence4 Sentence7
Sentence2 Sentence5 Sentence8
Sentence3 Sentence6 Sentence9
Great thanks & appreciation for any help!
Code for df1 & df2:
df1 <- data.frame(Group = c("AB", "AB", "AB", "XY", "XY", "XY", "ZW", "ZW", "ZW"),
Name = c("a", "b", "c", "d", "e", "f", "a", "b", "c"),
Vote = c("Sentence1", "Sentence2", "Sentence3", "Sentence4", "Sentence5", "Sentence6", "Sentence7", "Sentence8", "Sentence9"))
df2 <- data.frame(AB = c("a", "b", "c"),
XY = c("d", "e", "f"),
ZW = c("a", "b", "c"))