I would like to get the sum rows but excluding a given row. Listing all the variables is a bit tedious. I would like to highlight by position the variable to exclude in the operation. Any idea?
library(tidyverse)
df <- tribble(
~"var1", ~"var2", ~"var3", ~"var4",
"A", 20, 10, 23,
"B", 30, 6, 34,
"C", 40, 8, 23,
"D", 50, 10, 24
)
# This is the desired output
df %>%
rowwise() %>%
mutate(total = sum(var2, var3, var4))