I have 2 data frames of unequal size and I want to map values from the smaller data frame to the larger one based on the "color" column.
df1:
| Color | Value |
|---|---|
| Red | A |
| Blue | B |
| Green | C |
df2:
| Color | Repetition |
|---|---|
| Red | 1 |
| Green | 1 |
| Red | 2 |
| Blue | 1 |
| Blue | 2 |
| ... | ... |
Desired output:
| Color | Repetition | Value |
|---|---|---|
| Red | 1 | A |
| Green | 1 | C |
| Red | 2 | A |
| Blue | 1 | B |
| Blue | 2 | B |
| ... | ... | ... |
Reproducible code:
df1 <- data.frame(c("Red", "Blue", "Green"),
c("A", "B", "C"))
names(df1) <- c("Color", "Value")
df2 <- data.frame(c("Red", "Green", "Red", "Blue", "Blue"),
c(1,1,2,1,2))
names(df2) <- c("Color", "Repetition")
I've tried merge but it didn't work for me probably because they are of different sizes. I've also tried googling for this problem but have only found python solutions.