library(tidyverse)
chunk <- function(x, n){
split(x, sort(x %% n))
}
special_chunk <- function(x, n){
chunk(x, n) %>%
map(paste0, collapse = ", ") %>%
as.character()
}
special_chunk(1:6, 3)
#> [1] "1, 2" "3, 4" "5, 6"
aria <- tibble(rank = 1:50)
vec <- 1:150
aria %>%
mutate(extra_info = special_chunk(vec, 50)) %>%
separate(col = extra_info,
into = c("total_weeks",
"current",
"top_number"))
#> # A tibble: 50 x 4
#> rank total_weeks current top_number
#> <int> <chr> <chr> <chr>
#> 1 1 1 2 3
#> 2 2 4 5 6
#> 3 3 7 8 9
#> 4 4 10 11 12
#> 5 5 13 14 15
#> 6 6 16 17 18
#> 7 7 19 20 21
#> 8 8 22 23 24
#> 9 9 25 26 27
#> 10 10 28 29 30
#> # … with 40 more rows
Created on 2020-05-27 by the reprex package (v0.3.0)