I have a data frame as follows:
head(newStormObject)
FATALITIES INJURIES PROPVALDMG CROPVALDMG EVTYPE total
1 0 15 2.5
We can take the first value for all the other columns using slice
after updating the 'total' with the sum
of 'total'.
library(dplyr)
df1 %>%
group_by(EVTYPE) %>%
mutate(total = sum(total)) %>%
slice(1L) %>%
arrange(desc(total))
# FATALITIES INJURIES PROPVALDMG CROPVALDMG EVTYPE total
#
#1 0 15 250000 0 TORNADO 21
#2 0 0 0 0 HAIL 12
#3 0 0 0 0 TSTM WIND 1
NOTE: The 'total' for 'EVTYPE' "HAIL" is 12 based on the example