[R] Create new data frame with conditional sums

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Sun Oct 15 18:41:24 CEST 2023


Dear Jason,


I do not think that the solution based on aggregate offered by GPT was 
correct. That quasi-solution only aggregates for every individual level.


As I understand, you want the cumulative sum. The idea was proposed by 
Bert; you need only to sort first based on the cutoff (e.g. using an 
ordered factor). And then only extract the last value for each level. If 
Pct is unique, than you can skip this last step and use directly the 
cumsum (but on the sorted data set).


Alternatives: see the solutions with loops or with sapply.


Sincerely,


Leonard



More information about the R-help mailing list