Bin formation in a R data.frame
问题 I have a data.frame with two columns: category quantity a 20 b 30 c 100 d 10 e 1 f 23 g 3 h 200 I need to write a function with two parameters: dataframe , bin_size which runs a cumsum over the quantity column, does a split of the subsequent row if the the cumsum exceeds the bin_size and adds a running bin number as an additional column. Say, by entering this: function(dataframe, 50) in the above example should give me: category quantity cumsum bin_nbr a 20 20 1 b 30 50 1 c 50 50 2 c 50 50 3