Let's suppose I have the following dataframes:
test <- data.frame(X = c(1,2,3), Y = c(4,5,6), row.names = c("T1", "T2", "T3"))
test2 <- data.frame(mean = c(1,2,5), row.names = c("T1", "T2", "T3"))
I want to multiply all rows in the test dataframe by the value in the test2 dataframe, matched by row name. How do I do this to get an answer like this:
answer <- data.frame(X = c(1,4,15), Y = c(4,10,30), row.names = c("T1", "T2", "T3"))
You can do
test * test2[rownames(test), "mean"]
# X Y
# T1 1 4
# T2 4 10
# T3 15 30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With