This question already has an answer here:
I have a table that has been summed by quantity:
Product Average_Price Quantity
ABC 25 5
DFG 14 2
HIJ 9 3
I need to duplicate each row as many times as it's total (quantity) value. Like this:
Product Average_Price Quantity
ABC 25 1
ABC 25 1
ABC 25 1
ABC 25 1
ABC 25 1
DFG 14 1
DFG 14 1
HIJ 9 1
HIJ 9 1
HIJ 9 1
To make such transformation more explicit, Quantity should now reflect this (1 for each value)
Can this be done in Tidyverse?
Sample table:
df <- data.frame(product = c("ABC", "DFG", "HIJ"),
average_price = c(25, 14, 9),
quantity = c(5, 2, 3))