Hi there,
I'm having trouble with a simple volume bucketing script. Any help or pointers would be greatly appreciated.
Starting with 2 vectors, id and volume
> volume <- c(0,0,0,120,110,0,50,78,170,11,0,0,5,0,56,13,0,78)
> id <- seq(1,length(volume))
> v_id <- data.frame(id=id,volume=volume)
I'm wanting to create two new vectors. The first sums volume to a maximum level. If the cumulative sum for an id is greater than the max (bucket) level, the extra is given to the following bucket. These buckets are then given a consecutive number.
The output I've been trying to generate is
> bucket <- 150
> result
> id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
> volume
0 0 0 120 110 0 50 78 170 11 0 0 5 0 56 13 0 78
> bin_vol
0 0 0 120 150 80 130 150 150 89 89 89 94 94 150 13 0 91
> bin_num
1 1 1 1 1 2 2 2 3 4 4 4 4 4 5 5 5 5
Thanks in advance
I'm having trouble with a simple volume bucketing script. Any help or pointers would be greatly appreciated.
Starting with 2 vectors, id and volume
> volume <- c(0,0,0,120,110,0,50,78,170,11,0,0,5,0,56,13,0,78)
> id <- seq(1,length(volume))
> v_id <- data.frame(id=id,volume=volume)
I'm wanting to create two new vectors. The first sums volume to a maximum level. If the cumulative sum for an id is greater than the max (bucket) level, the extra is given to the following bucket. These buckets are then given a consecutive number.
The output I've been trying to generate is
> bucket <- 150
> result
> id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
> volume
0 0 0 120 110 0 50 78 170 11 0 0 5 0 56 13 0 78
> bin_vol
0 0 0 120 150 80 130 150 150 89 89 89 94 94 150 13 0 91
> bin_num
1 1 1 1 1 2 2 2 3 4 4 4 4 4 5 5 5 5
Thanks in advance
Last edited: