Think about the following two data frames
df1 <- data.frame(a = rep(1, 10), b = rep(1, 10), c = rep(1, 10))
df2 <- data.frame(company = c("a", "b", "c"), weight = c(5, 10, 20))
df1
a b c
1 1 1 1
2 1 1 1
3 1 1 1
4 1 1 1
5 1 1 1
6 1 1 1
7 1 1 1
8 1 1 1
9 1 1 1
10 1 1 1
df2
company weight
1 a 5
2 b 10
3 c 20
I'm now looking for a solution that looks for the column names of df1 in the company column of df2 and multiplies each row of the corresponding company in df1 with the value from the weight column.
So what I want to achieve is:
df.weighted
a.weighted b.weighted c.weighted
1 5 10 20
2 5 10 20
3 5 10 20
4 5 10 20
5 5 10 20
6 5 10 20
7 5 10 20
8 5 10 20
9 5 10 20
10 5 10 20
Does anyone have an idea?
Thank you!