Nest a data frame by chunks containing all elements of a group
Usage
nest_chunk(data, .by, chunks)
Arguments
- data
A data frame.
- .by
A column which values should be.
- chunks
Integer. Number of chunks.
Value
A nested data frame.
Examples
data <- tibble::tibble(id = c(1, 1, 1, 2, 3))
out <- nest_chunk(data, .by = "id", chunks = 3)
out$data
#> [[1]]
#> # A tibble: 3 × 1
#> id
#> <dbl>
#> 1 1
#> 2 1
#> 3 1
#>
#> [[2]]
#> # A tibble: 1 × 1
#> id
#> <dbl>
#> 1 2
#>
#> [[3]]
#> # A tibble: 1 × 1
#> id
#> <dbl>
#> 1 3
#>