0

I have a dataset of the form

Order ID Item_Name.0 Quantity.0 Price.0 Item_Name.1 Quantity.1 Price.1 Item_Name.2 
Quantity.2 Price.2
3231232  CTR   2 200 VCF 1 140 Ztr 3 450
3561232  TRC   5 600 ErD 6 540 XdZ 1 420
323243  BCF   4 300 DVC 1 440 fdZ 1 145
3431232  RAC   2 20 VfdD 2 110 YfdZ 4 400 

Now, I want to model it into a data frame of the form

Order ID Item_Name Quantity Price  
3231232  CTR   2 200
3231232  VCF 1 140  
3231232  Ztr 3 450
3561232  TRC   5 600
3561232  ErD 6 540
3561232  XdZ 1 420
323243  BCF   4 300
323243  DVC 1 440 
323243  fdZ 1 145
3431232  RAC   2 20
3431232  VfdD 2 110
3431232  YfdZ 4 400 

I tried the gather() and melt() function in R but to no effect. Any help on how to go about this would be appreciated.

talat
  • 68,970
  • 21
  • 126
  • 157
  • There are dupes for this, Try `library(data.table);melt(setDT(df1), measure = patterns ("Item_Name", "Quantity", "Price"), value.name = c("Item_Name", "Quantity", "Price"))` – akrun Jul 20 '17 at 11:27
  • 1
    Hi. Thanks it did work out well. – Karan Aulakh Jul 21 '17 at 06:11

0 Answers0