I have a dataframe with a lot of columns.
LABEL COL1 COL2 COL3 Meat 10 20 30 Veggies 20 30 40
How do I make column named
You can use this function, which takes advantage of select_if and scoped argument is_numeric
select_if
is_numeric
myfun <- function(df) { require(dplyr) y <- select_if(df, is_numeric) rowSums(y, na.rm=T) }
df$SUMCOL <- myfun(df)
LABEL COL1 COL2 COL3 SUMCOL 1 Meat 10 20 30 60 2 Veggies 20 30 40 90