Cut and aggregate run length encoding <NA>

na_rle_cut(x, by)

Arguments

x

An object returned by na_rle() or list_of_na_rle().

by

A function applied to indices, such as tsibble's period functions and lubridate's friends.

Value

A tibble contains:

  • indices: aggregated indices.

  • n_run: the number of unique runs for each by.

  • n_na: the total number of NAs for each by.

See also

Other rectangling functions: na_rle_expand

Examples

if (!requireNamespace("nycflights13", quietly = TRUE)) { stop("Please install the nycflights13 package to run these following examples.") } if (!requireNamespace("tidyr", quietly = TRUE)) { stop("Please install the tidyr package to run these following examples.") } library(dplyr, warn.conflicts = FALSE) nycflights13::weather %>% group_by(origin) %>% summarise(wind_gust_na = list_of_na_rle(wind_gust, time_hour)) %>% mutate(wind_gust_na = na_rle_cut(wind_gust_na, by = tsibble::yearmonth)) %>% tidyr::unnest(cols = wind_gust_na)
#> # A tibble: 36 x 4 #> origin indices n_run n_na #> <chr> <date> <int> <int> #> 1 EWR 2013-01-01 55 583 #> 2 EWR 2013-02-01 50 482 #> 3 EWR 2013-03-01 84 480 #> 4 EWR 2013-04-01 59 514 #> 5 EWR 2013-05-01 52 600 #> 6 EWR 2013-06-01 56 548 #> 7 EWR 2013-07-01 62 632 #> 8 EWR 2013-08-01 39 657 #> 9 EWR 2013-09-01 45 616 #> 10 EWR 2013-10-01 51 629 #> # … with 26 more rows