I am exploring some data with R, and looking for smart method for computing a new row with the total of the numeric columns. I give below a dummy example :
tibble(
Group = c("Crew", "1st class", "2nd class", "3rd class"),
Deaths = c(673, 122, 167, 528),
Survivors = c(212, 203, 118, 178)
) %>%
add_row(Group = "Total", Deaths = sum(.$Deaths),
Survivors = sum(.$Survivors))
I am not really satisfied of this code, and wonder wether it exists a more elegant method using dplyr. But it leads me to a simple question : why can't I replace .$Deaths
by .data$Deaths
?
I often develop package and I am always struggle for removing the checking notes. In that case, I would not be able to remove the dot expression...
Can anyone provide an alternative solution or at least an explanation ?
Thanks in advance ;-)