Created
October 2, 2018 08:31
-
-
Save dmi3kno/2ae8c0a4c2e7b138c8d37c7995ef7b13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1) | |
tibble::tibble(year = seq(1900,1999) * | |
sample(c(1, NA), 100, replace = TRUE), | |
value=runif(100), | |
gap_id=inverse.rle(structure(list(lengths=rle(is.na(year))$lengths, | |
values=cumsum(rle(is.na(year))$values)* | |
rle(is.na(year))$values), class="rle"))) | |
#> # A tibble: 100 x 3 | |
#> year value gap_id | |
#> <dbl> <dbl> <int> | |
#> 1 1900 0.655 0 | |
#> 2 1901 0.353 0 | |
#> 3 NA 0.270 1 | |
#> 4 NA 0.993 1 | |
#> 5 1904 0.633 0 | |
#> 6 NA 0.213 2 | |
#> 7 NA 0.129 2 | |
#> 8 NA 0.478 2 | |
#> 9 NA 0.924 2 | |
#> 10 1909 0.599 0 | |
#> # ... with 90 more rows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment