I have the following code for calculating certain quantities of interest, specifically the sum of the two right-most columns.
library(dplyr)
library(janitor)
m = c(0, 0.8, 2.3, 4.1, 2.1)
l = c(0.3, 0.8, 0.9, 0.75, 0.25)
mytable = data.frame(l, m)
rownames(mytable) = paste("Group", 1:5)
# Initial population
n0 = c(1,1,1,1,1)
mytable = mytable %>%
mutate(lm = l * m) %>%
mutate(n = n0) %>%
mutate(offspring = lm * n) %>%
adorn_totals("row")
This gives the following output:
> mytable
l m lm n offspring
0.3 0.0 0.000 1 0.000
0.8 0.8 0.640 1 0.640
0.9 2.3 2.070 1 2.070
0.75 4.1 3.075 1 3.075
0.25 2.1 0.525 1 0.525
Total 9.3 6.310 5 6.310
I have the following issues:
- How to isolate the column totals for specific columns? In my case, I would like the column totals for just columns
n
andoffspring
. I read the documentation for theadorn_totals()
function but I could not figure out how to do this. - The row names assigned are missing. How can I make the row names appear and have the word "Total" as the row name for the new row of column totals?
- The row total does not appear for the first column, which is strange.