In the following DF, called "contribs," is there a way to quickly calculate the sums in the amount column based on state? In other words, the sum of the amount from all rows that have CA in the state column, and then all rows that have NV in the state column, etc., similar to the "groupby" method in pandas.
name,state,amount
JASON HOPE,AZ,15000
MONA GIRODET,CA,5000
SHINCHI CHIEN,NV,5000
JEFF KREITZMAN,AZ,5000
GRISELDA KREITZMAN,AZ,5000
BOB DAY,CA,5000
JAMES BRESLO,CA,5000
JOHN SCARDINO,CA,5
JOHN SCARDINO,CA,5000
ANTHONY TESORO,CA,100
ANTHONY TESORO,CA,100
ANTHONY TESORO,CA,5000
Here's the way I've been doing it:
ca_contribs <- contribs$state == "CA"
sum(ca_contribs$amount)
And then I do that for each state in the data and put the results together in a dataframe, but is there a more efficient way to do this?