Is it possible to refer to 'all columns' or a range of columns in combination with rowwise()
in dplyr
without having to enumerate all individual column names?
For example, in the following, I would rather not specify each of the first 7 column names, but rather say 1:7
or something. Can't seem to get it to work. Must be missing something simple.
mtcars %>%
rowwise() %>%
mutate(sillyMetric = mean(c(mpg, cyl, disp, hp, drat, wt, qsec))) %>%
.$sillyMetric
Please don't tell me how I don't need rowwise()
for this case. I obviously have a different problem I am trying to solve that requires it. I want to know if there is a way to not have to enumerate all column names with rowwise
. I DON'T want any other solutions that compute this above sillyMetric
more efficiently.