My current data:
Type Country Score
University Australia 10
University Brazil 10
University Hong Kong 10
College Australia 10
College Brazil 10
College Hong Kong 10
Now, I want to have a summary of new rows created from the above data as shown below. The new rows are a sum of the scores for each university and college in a country.
Type Country Score
University Australia 10
University Brazil 10
University Hong Kong 10
College Australia 10
College Brazil 10
College Hong Kong 10
All Australia 20
All Brazil 20
All Honk Kong 20
I know I can write a loop to iterate over the data and check the countries but maybe I can use packages like dplyr to achieve what I want.
df1 %>% group_by(Col1, Col2) %>% summarise(col3 = sum(col3)) %>% ungroup %>% mutate(Col1 = 'All') %>% bind_rows(df1, .)