I would like to multiply several columns from a certain data.frame * df1* with the Percentages matching the headers of the columns in * df1*. These are given in data.frame df2, column 1, called ID. I would like the output to be as in df3.
Note that my dataset is large. There are 13.000 rows and 33 columns in df1. There are 136 rows and 3 columns in df2.
What is the best way to handle this?
Examples of df1, df2, df3 are given below.
df1:
Date V1 V2 V3 V4
1/1/2000 0 0.4 0 0
2/1/2000 0 0.1 0 0.1
3/1/2000 0.5 0 0 1
4/2000 0.8 1.5 1 1
df2:
ID Subbasin Percentage
V1 001 0.4
V4 001 0.6
V1 002 0.2
V2 002 0.8
V1 003 0.1
V2 003 0.3
V3 003 0.2
V4 003 0.4
df3:
Date 001 002 003
1/1/2000 0 0.32 0.12
2/1/2000 0.06 0.08 0.07
3/1/2000 0.8 0.1 0.45
4/2000 0.92 1.36 1.13
I guess I have to start with omitting the Date, with
df1 <- NULL