I have a dataset DF
structure(list(Company= c("ABC", "ABC",
"ABC", "ABC", "ABC",
"ABC", "ABC", "XYZ",
"XYZ", "XYZ"), year = 1951:1960,
dummyconflict = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("0", "1"), class = "factor")), row.names = 2:11, class = "data.frame")
I want to add another column such that it increases counts upwards. That is should a Company move from level “1” to “0” over a year, the count starts with one and if it has level “1” for the year after the count continues; 2,3,4,5,6 etc. Should it however move back to “0” again, the count starts over again with zero..
Please help in adding another column based on above condition
EXPECTED RESULTS in image