A simplified version of my data looks like:
year title name
2019 x a
2019 y b
2018 x a
2018 y a
2017 x c
2017 y a
2016 x a
2016 y b
I would like to create a new dataframe that would look like this:
name title year runtot
a x 2016 1
a x 2017 1
a x 2018 2
a x 2019 3
a y 2016 0
a y 2017 1
a y 2018 2
a y 2019 2
a xy 2016 1
a xy 2017 2
a xy 2018 4
a xy 2019 5
b x 2016 0
b x 2017 0
b x 2018 0
b x 2019 0
b y 2016 1
b y 2017 1
b y 2018 1
b y 2019 2
b xy 2016 1
b xy 2017 1
b xy 2018 1
b xy 2019 2
c ...
Regarding runtot
, the new column I want to create, I would like to do the running total for each of the values in the name
column. In other words, I would like to know how the running total grows separately for a
, how it grows for b
, how it grows for c
, etc.
I have tried subsetting the data but I could not get an approximate result of what I want.
Any ideas or suggestions?