Skip to content
Advertisement

Grouping of a dataframe monthly after calculating the highest daily values

I’ve got a dataframe with two columns one is datetime dataframe consisting of dates, and another one consists of quantity. It looks like something like this,

JavaScript

I want to make another dataframe. It should consist of two columns one is Month/Year and the other is Till Highest. I basically want to calculate the highest quantity value until that month and group it using month/year. Example of what I want precisely is,

JavaScript

In my case, the dataset is vast, and I’ve readings of almost every day of each month and each year in the specified timeline. Here I’ve made a dummy dataset to show an example of what I want.

Please help me with this. Thanks in advance :)

Advertisement

Answer

In R you can use cummax:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement