I am trying to get sums in r. I have 2 dataframes. One consists of 3 columns (tag, doy (=day of year) at beginning, doy at end). The other consists of 2 columns (doy, bbb (=an amount per day)).

Now I want for each row of df1 the sum of bbb from doy.0 to doy.end. 

```
# creating df1
tag<-c(1:5)
doy.0<-c(200:204)
doy.end<-c(207:211)
df1<-data.frame(tag, doy.0, doy.end)

# creating df2
doy<-c(200:211)
bbb<-c(12,10,18,16,20,11,15,19,25,23,21,20)
df2<-data.frame(doy,bbb)

  tag doy.0 doy.end
1   1   200     207
2   2   201     208
3   3   202     209
4   4   203     210
5   5   204     211

  doy bbb
1  200  12
2  201  10
3  202  18
4  203  16
5  204  20
6  205  11
7  206  15
8  207  19
9  208  25
10 209  23
11 210  21
12 211  20

```

So I want an additional column in df1 with the sum of bbb. For example for tag 1, I want the bbb from doy 200 to doy 207 (it should be 121 for tag 1, 134 for tag 2, etc). 

I have played around a bit with for loops but couldnt figure it out. I would really appreciate your help!
Also if you can think of a better title to this question, feel free to change it. I dont even know what to call this problem, thats how annoying it is...