Similar to: mutate rowSums exclude one column but in my case, I really want to be able to use select
to remove a specific column or set of columns
I'm trying to understand why something of this nature, won't work.
d <- data.frame(
Alpha = letters[1:26],
Beta = rnorm(26),
Epsilon = rnorm(26),
Gamma = rnorm(26)
)
I thought this would work, but it's giving me a strange error:
# Total = Beta + Gamma
d <- mutate(d,Total = rowSums(select(d,-Epsilon,-Alpha)))
Error: All select() inputs must resolve to integer column positions.
The following do not:
* -structure(1:26, .Label = c("a", "b", "c", "d", "e", "f", "g", "h", "i...
In addition: Warning message:
In Ops.factor(1:26) : ‘-’ not meaningful for factors
I'd like to be able to do this in a long chain, and keep it "dplyr style"... it strikes me as odd that this is so difficult given that it's really straightforward without using typical dplyr syntax:
d$Total <- rowSums(select(d, -Alpha, -Epsilon)) # This works!