I am trying to flag parts of a data series with a unique label (or number), preferably using dplyr. I can flag those sections as 1 or 0, but how to turn each chunk of 1 into "A" (or 1), the second chunk into "B" (or 2), etc.?
A basic dataset would be:
dat <- dat <- c(rep(1,3), rep(0,5), rep(1,3), rep(0,7), rep(1,4), rep(0,3) )
Which is:
1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0
And I want to get:
1 1 1 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 3 3 3 3 0 0 0
Or:
A A A NA NA NA NA NA B B B NA NA NA NA NA NA NA C C C C NA NA NA
First question here after reading hundreds of them...