I am trying to mutate wanted, which will store the values of x separated by comma. Note that wanted can contain maximum three numbers (wanted will have only one row if x has three rows).
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# toy data
df <- tibble(x = 6:13)
df1 <- df |>
mutate(linenr = 1 + (row_number()-1)%/%3)|>
nest_by(linenr,.key="data") |>
mutate( wanted = paste(data$x,collapse=',')) |>
ungroup() |>
select(-c(linenr,data)) |>
print()
#> # A tibble: 3 x 1
#> wanted
#> <chr>
#> 1 6,7,8
#> 2 9,10,11
#> 3 12,13
Created on 2021-12-13 by the reprex package (v2.0.1)