R sum a variable by two groups
问题 I have a data frame in R that generally takes this form: ID Year Amount 3 2000 45 3 2000 55 3 2002 10 3 2002 10 3 2004 30 4 2000 25 4 2002 40 4 2002 15 4 2004 45 4 2004 50 I want to sum the Amount by ID for each year, and get a new data frame with this output. ID Year Amount 3 2000 100 3 2002 20 3 2004 30 4 2000 25 4 2002 55 4 2004 95 This is an example of what I need to do, in reality the data is much larger. Please help, thank you! 回答1: You can group_by ID and Year then use sum within