Given a dataframe
category <- c("A", "B", "C")
r1 <- c(2, 2, 2)
r2 <- c(3, 3, 3)
r3 <- c(1, 1, 1)
r4 <- c(4, 4, 4)
df <- data.frame(category, r1, r2, r3, r4)
How do I calculate and add a new row D
by multiplying values in A
and B
per column and dividing by the sum of C
?