I have one table containing data which looks like this
Samp depth value
A1 0 2
A1 1 4
A1 2 3
A1 3 6
A1 4 8
A1 5 6
A1 6 2
A1 7 3
A2 0 2
A2 1 8
A2 2 6
A2 3 3
A2 4 6
A2 5 6
A3 0 7
A3 1 3
A3 2 2
A3 3 8
A3 4 3
...
Second table with intervals
Samp d_top d_bot
A1 0 2
A2 0 5
A3 1 2
A4 3 5
...
Now I would like to query the first table, using intervals from the second table.
Samp d_int sum_value
A1 0-2 9
A2 0-5 29
A3 1-2 5
...
It should work with aggregate or ddply, by specifying a list, which I tried. The problem is that it is not fixed intervals, but as defined in the second table. Any help is appreciated.