dplyr - mutate formula based on similarities in column names
I am trying to find a better way to run a mutate() on a combination of columns based on parts of the column names. For example, a way to simplify the mutate function in the following code: df <- data.frame(LIMITED_A = c(100,200), UNLIMITED_A = c(25000,50000), LIMITED_B = c(300,300), UNLIMITED_B = c(500,500), LIMITED_C = c(2,10), UNLIMITED_C = c(5,20)) df %>% mutate(FINAL_LIMITED = (LIMITED_A - LIMITED_B) / LIMITED_C, FINAL_UNLIMITED = (UNLIMITED_A - UNLIMITED_B) / UNLIMITED_C) A formula with the form: (._A - ._B) / ._C and the result is given the name FINAL_. Is there a way to simplify this to