I have two data frames, df1 has stock symbols and values. df2 correlations with the same names but arranged as rows. df1 has many more columns than df2, but all columns that are in df2 exist in df1. I need to multiply matching columns and store newly created values as a new dataframe. The new dataframe will only have a stock symbol and then all multiplications of df1*df2. The data looks like this:
df1
A Company Symbol Earn.GR MF Effic MF
TRUE 1.320005832 -0.080712181
df2:
Variable Corr
1 Val MF 0.312140675
2 Earn.GR.withCorr MF 0.992410721
I have tried this code, but not getting the expected result: Transpose df2:
df2 <- transpose (df2)
rownames(df2) <- colnames(df2)
Match and multiply columns
df3 <- df1[names(df1) %in% names(df2)] <- sapply(names(df1[names(df1) %in% names(df2)]),
function(x) df1[[x]] * df2[[x]])
Thanks in advance.