I have three tables that I'm attempting to merge into one.
The main table is similar to:
Table1 <- data.frame("Data" = c(1, 2, 3, 4, 5), "Desc" = c("A", "A", "A", "B", "B"))
TableA <- data.frame("Values" = c(6, 2, 3))
TableB <- data.frame("Values" = c(2, 7))
I want to add another column to Table1 with the values from TableA and TableB, but Values coming from TableA must be placed in a row containing "A" in the "Desc" column and TableB values in rows containing "B" in the "Desc" column. The number of rows in Table A equal the number of rows Table1 with "A" and same for TableB.
The resulting Table should look like:
Table1 <- data.frame("Data" = c(1, 2, 3, 4, 5), "Desc" = c("A", "A", "A", "B", "B"), "Values" = c(6, 2, 3, 2, 7))
> Table1
Data Desc Values
1 1 A 6
2 2 A 2
3 3 A 3
4 4 B 2
5 5 B 7