Hi
I have a tibble and want to have a sequence according to the grouping Goods/COICOP:
test <- tribble(
~Goods , ~COICOP ,~Value ,~G , ~Begin, ~End,
"G01-03", "c01_1_1", 0.025, "01-03", 1 , 3,
"G01-03", "c01_1_1", 0.025, "01-03", 1 , 3,
"G01-03", "c01_1_1", 0.025, "01-03", 1 , 3,
"G01-03", "c01_1_3", 0.025, "01-03", 1 , 3,
"G01-03", "c01_1_3", 0.025, "01-03", 1 , 3,
"G01-03", "c01_1_3", 0.025, "01-03", 1 , 3)
test <- test %>%
mutate(G1 = Begin)
group_by(COICOP, Goods) %>%
mutate(G1 = ifelse(!is.na(lag(G1)), G1 +1, G1))
G1 should look like 1,2,3,1,2,3. However, I only manage to get 1,2,2,1,2,2.
Any idea how to correct this?
Cheers
Renger