R – dataframe – every x rows new number in other column

Do you look for something like this:

tibble(productID = 1:4, week = 5:8, order = "Test") %>% 
 tidyr::complete(week = 1:26, productID = 1:4, fill = list(order = NA_character_))

# A tibble: 104 x 3
    week productID order
   <int>     <int> <chr>
 1     1         1 NA   
 2     1         2 NA   
 3     1         3 NA   
 4     1         4 NA   
 5     2         1 NA   
 6     2         2 NA   
 7     2         3 NA   
 8     2         4 NA   
 9     3         1 NA   
10     3         2 NA   
# ... with 94 more rows

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top