A quick question with hopefully a quick answer.
I was trying to use rowSums only on columns that had numeric data. I want to do something equivalent to this (using the built-in data set CO2 for a reproducible example):
# Reproducible example
CO2 %>%
mutate( Total = rowSums(.[c(-1, -2, -3)]) ) %>%
head()
Plant Type Treatment conc uptake Total
1 Qn1 Quebec nonchilled 95 16.0 111.0
2 Qn1 Quebec nonchilled 175 30.4 205.4
3 Qn1 Quebec nonchilled 250 34.8 284.8
4 Qn1 Quebec nonchilled 350 37.2 387.2
5 Qn1 Quebec nonchilled 500 35.3 535.3
6 Qn1 Quebec nonchilled 675 39.2 714.2
I tried rowSums with mutate and is.numeric, but no success. Is there an easy way to do this?
# How do sum rows using is.numeric (below does not work)?
CO2 %>%
mutate( Total = rowSums(., is.numeric(.)) )