I have a df (partially listed below).
    account    company           sum
1    202003         B01        40.50
2    208001         B01    -71596.73
3    280250         B01     -6652.70
4    200001         B13     44362.77
5    202001         B13     13874.25
6    204001         B13      5744.20
7    204102         B13       295.00
8    285091         B13    317145.15
9    286101         B13     11471.13
10   298001         B13    396096.50
I am trying to add the numbers in the df1$sum column into a new dataframe based on the following criteria:
For each company (B01 and B13) I need to aggregate the column df1$sum for all accounts in df1$accounts beginning with ^20 and call it df2$Expenses1 (so in this example that would be 202003 and 208001 for company B01). 
Separately I need to aggregate all of the accounts beginning with ^28 and ^29 and call it df2$Expenses2(so for company B01 it would only be account 280250 and for company B13 it would be the sum of accounts 285091, 286101 and298001).
Ultimately, the new data frame df2 should look something like this:
Company   Expenses1   Expenses2
 B01     -71,556.23    -6,652.7
 B13      64,276.22  724,712.78    
Would really appreciate some help with this!
 
     
    