I have 2 data frames and I would like to add a column to one and add values from another data frame based on matching conditions. I would then like to repeat this for many large datasets.
# Example dataframe
DF1 <- data.frame(Batch = c('a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b'),
Patch1 = c(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3),
Patch2 = c(2, 3, 1, 3, 1, 2, 2, 3, 1, 3, 1, 2))
DF2 <- data.frame(Batch = c('a', 'a', 'a', 'b', 'b', 'b'),
Patch = c(1, 2, 3, 1, 2, 3),
Pop_size = sample(1:300, size=6, replace=TRUE))
To DF1 I would like to add 2 columns (Patch1_popsize and Patch2_popsize) where the Pop_size is given in DF2 with corresponding Patch numbers for a given Batch