Below code create new variable a_new/b_new/c_new
, but have to input code in mutate one by one. Is there any convenient way ?
In actual, I have to create many variable ,for instance a_new/b_new/..../z_new
. I don't want to input the variable calculating code one by one.
library(tidyverse)
test_data <- data.frame(a=c(1:3),
b=c(3:5),
c=c(1:3),
a_increase=c(1:3)/100,
b_increase=c(3:5)/100,
c_increase=c(6:8)/100)
test_data %>% mutate(
a_new =a* a_increase,
b_new =b* b_increase,
c_new =c* c_increase
)