One way to do this is to add it all of the sizes in as a list column containing the vector of sizes. Then use unnest_longer()
to expand it out into rows.
library(dplyr)
library(tidyr)
# this should work with all the columns
data <- tibble(parent_sku = paste0("ABBBOA0", 1:4),
stock_status = rep("instock", 4))
sizes <- c("M", "L", "XL", "XXL")
data %>%
mutate(attribute_size = list(sizes)) %>%
unnest_longer(attribute_size)
Which gives you the expansion...
# A tibble: 16 x 3
parent_sku stock_status attribute_size
<chr> <chr> <chr>
1 ABBBOA01 instock M
2 ABBBOA01 instock L
3 ABBBOA01 instock XL
4 ABBBOA01 instock XXL
5 ABBBOA02 instock M
6 ABBBOA02 instock L
7 ABBBOA02 instock XL
8 ABBBOA02 instock XXL
9 ABBBOA03 instock M
10 ABBBOA03 instock L
11 ABBBOA03 instock XL
12 ABBBOA03 instock XXL
13 ABBBOA04 instock M
14 ABBBOA04 instock L
15 ABBBOA04 instock XL
16 ABBBOA04 instock XXL
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…