I am trying to get both the sum across rows and the max value in a row. I obviously do not want the rowsum column to be included in the max values, nor do i want the max values included in the row sum. I need a final dataset that has both of these columns retained however.
Using dplyr
I tried-
iris<- iris %>%
mutate(readsum = rowSums(across(where(is.numeric)), na.rm=TRUE))
iris_max<- iris %>%
rowwise()%>%
select(-"readsum")%>%
mutate(readmax = max(across(where(is.numeric)), na.rm=TRUE))
but this just removed readsum
from the new df
I would like to get as output:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species readsum readmax
<dbl> <dbl> <dbl> <dbl> <fct> <dbl> <dbl>
1 5.1 3.5 1.4 0.2 setosa 10.2 5.1
2 4.9 3 1.4 0.2 setosa 9.5 4.9
3 4.7 3.2 1.3 0.2 setosa 9.4 4.7
4 4.6 3.1 1.5 0.2 setosa 9.4 4.6
5 5 3.6 1.4 0.2 setosa 10.2 5
6 5.4 3.9 1.7 0.4 setosa 11.4 5.4