I have a data frame that looks like the following
sample_data <- data.frame(Cohort = c("Q1", "Q2", "Q3", "Q4"),
Cohort.Size = c(120, 234, 345, 222),
MO1 = c(8.3, 7.1, 2.4, 5.4),
MO2 = c(6.6, 3.2, 5.3, NA),
MO3 = c(2.3, 4.5, NA, NA),
MO4 = c(4.5, NA, NA, NA))
As you can see, the second column Cohort.Size
consists of absolute numbers whereas all remaining columns MO1, MO2, MO3, MO4
show percentages. Is there an easy solution how I could multiply the percentage values with the corresponding value in the first column in order to get absolute numbers?
The result I am looking for would be the following table:
Cohort | Cohort.Size | MO1 | MO2 | MO3 | MO4
Q1 | 120 | 9.96 | 7.92 | 2.76 | 5.4
Q2 | 234 | 16.6 | 7.49 | 10.53|
Q3 | 345 | 8.28 | 18.29| |
Q4 | 222 | 11.99| | |
Thank you!