In the spirit of similar questions along these lines here and here, I would like to be able to sum across a sequence of columns in my data_frame
& create a new column:
df_abc = data_frame(
FJDFjdfF = seq(1:100),
FfdfFxfj = seq(1:100),
orfOiRFj = seq(1:100),
xDGHdj = seq(1:100),
jfdIDFF = seq(1:100),
DJHhhjhF = seq(1:100),
KhjhjFlFLF = seq(1:100),
IgiGJIJFG= seq(1:100),
)
# this does what I want
df_abc %>%
mutate(
sum_1 = orfOiRFj + xDGHdj + jfdIDFF + DJHhhjhF
)
Clearly, if there are a lot of variables in this sequence, typing them out is not feasible. Also, the names of the variables are not regex-friendly, so cannot be selected by a rule, other than the fact that they occur in a sequence.
I am hoping that there exists an abstraction in the tidyverse, that allows something like:
df_abc %>%
mutate(
sum_1 = sum(orfOiRFj:DJHhhjhF)
)
Thanks.