I have a dataframe in R of this form currently
city product inv pla
city1 product1 0 2
city1 product2 1 2
city1 product3 2 2
city1 product4 0 1
city1 product5 1 1
city1 product6 1 1
I need to duplicate the rows when pla = 2, but put a value in the inv column according to the following:
When inv = 0, both rows must be equal to 0. When inv = 1, the first row must be equal to 1, and the second row must be equal to 0. When inv=2, both rows must equal 1.
How do I create a dataframe like this?:
city product inv pla
city1 product1 0 2
city1 product1 0 2
city1 product2 1 2
city1 product2 0 2
city1 product3 1 2
city1 product3 1 2
city1 product4 0 1
city1 product5 1 1
city1 product6 1 1