0

I used this question and answer to get what I want (how to compute rowsums using tidyverse), but I was wondering if there was a way to do named subsetting with rowSums. I can imagine an instance where I have a lot of variables where this would be desirable.

What I mean is something like this:

rosSums(iris, Sepal.Length, Sepal.Width)

Instead of:

rowSums(iris[1:2])

Thanks for any help in advance!

Ben G
  • 4,148
  • 2
  • 22
  • 42
  • `rowSums(iris[, c("Sepal.Length", "Sepal.Width")])` – Roland Aug 08 '18 at 12:01
  • or if you are trying to index columns like 1:2 `rowSums(iris[,c(grep("Sepal.Length",colnames(iris)):grep("Sepal.Width",colnames(iris)))])` – AndS. Aug 08 '18 at 12:05

1 Answers1

1

using dplyr you could simply do.

iris %>% mutate(Sepal.Length + Sepal.Width)
Adam Wheeler
  • 393
  • 1
  • 11