Dear Forum,

I have following data.frame as

fraud_data = data.frame(no_of_frauds = c(1, 2, 4, 6, 7, 9, 10), frequency = 
c(3, 1, 7, 11, 13, 1, 4))

> fraud_data
  no_of_frauds frequency
1            1         3
2            2         1
3            4         7
4            6        11
5            7        13
6            9         1
7           10         4


I need to regroup the data in such a way that if the frequency is less than 5, 
the corresponding class data gets merged to next class i.e. the frequencies get 
added added till the added frequencies exceed 5. Thus, in above data.frame 
since frequencies pertaining to no_of_frauds 1 and 2 are 3 and 1 respectively, 
these get added to class 4 and the frequency of this class now becomes 3+1+7 = 
11. Likewise, frequency of classes 9 and 10 are 1 and 4 and when these are 
added still it is 5 i.e. doesn't exceed 5. Thus, these should get added to the 
previous class i.e. 7.

Thus I need to have

no_of_frauds       frequency
        4                   11            #  ( 3 + 1 + 7)
        6                   11           
        7                   18            #  (13 + 1 + 4)

Kindly guide

Regards

Katherine
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to