简体   繁体   English

R - 数据框 - 其他列中每 x 行新数字

[英]R - dataframe - every x rows new number in other column

my question is:我的问题是:

I have a matrix of 200.000 rows and 3 different columns (productID, week, order).我有一个包含 200.000 行和 3 个不同列(productID、week、order)的矩阵。 I want to put the productID (starting with 1) in the product column and create 26 rows for each ID.我想将 productID(从 1 开始)放在 product 列中,并为每个 ID 创建 26 行。 Than I want to put 1-26 in the week column for every ID.我想在每个 ID 的周列中放置 1-26。

I know it's not that hard, but I keep making mistakes.我知道这并不难,但我一直在犯错。

Thank you so much for your help!非常感谢你的帮助!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM