r - Summing all columns by group -
I think this is an incredibly easy answer, but I think that around my head collecting or casting Can not find multiple conditions
I have a table that looks like this:
& gt; Head (DF, N = 10 L) State EVTYPE FATALITIES INJURIES 1 AL TORNADO 0 15 3 AL TORNADO 0 2 4 AL TORNADO 0 2 6 AL TORNADO 0 6 7 AL TORNADO 0 1 9 AL TORNADO 1 14 11 AL TORNADO 0 3 12 AL TORNADO 0 3 13 AL TORNADO 1 26 Obviously it goes ... What do I do to state and EVTYPE Summing Fatalities and because of the injury I If these 10 rows were my full dataset then the result would be a single row data frame:
state EVTYPE FATALITIES INJURIES 1 AL TORNADO 2 74 My entire frame There are several states and many EVTYPES
< P> You can try
Library (dplyr) df% & gt;% group_by (state, EVTYPE)% & gt;% summary_a (fun (amount))< / Ex>or
Total (. STATE + EVTYPE, df, sum)
Comments
Post a Comment