is there a way to select number of columns without explicitly typing the column names. This is more for automation purposes. Consider the following code
a <- c("people", "contracts", "design")
b <- as.numeric(c(1,2,3))
c <- as.numeric(c(2,3,4))
d <- as.numeric(c(5,6,7))
df <- data.frame(cbind(a, b, c, d))
df$b <- as.numeric(df$b)
df$c <- as.numeric(df$c)
df$d <- as.numeric(df$d)
library(dplyr)
df %>%
rowwise() %>%
mutate(total = sum(b, c, d))
In this example I have added the values of column b, c and d in a row wise fashion. In future exports, there will be columns e, f, g and so on....
Is there a better way to perform this operation as so I don't have to type the columns individually assuming all columns from "b" onwards will always be numeric. It is only column A which is a character.