I have this tibble:
tibble(country = c("USA","USA","USA","USA","CHINA","CHINA","CHINA","CHINA","SPAIN","SPAIN","SPAIN","SPAIN"),
values = c(10,20,100,30,60,70,80,90,100,20,100,90))
how can i make the following column - the condition is population column starts at value 1 and increments by +1, when the values == 100, it resets to the value 1 and increment starts again - see last example SPAIN where the change happens twice.
So final tibble is:
tibble(country = c("USA","USA","USA","USA","CHINA","CHINA","CHINA","CHINA","SPAIN","SPAIN","SPAIN","SPAIN"),
values = c(10,20,100,30,60,70,80,90,100,20,100,90),
population = c(1,2,1,2,1,2,3,4,1,2,1,2))
Any help given thanks