0

I'm trying to convert some order details in R. I have the data as below:

Order ID   Product Name
1          A
1          B
1          C
2          E
2          F
2          D

And I need to convert this to as below:

Order ID   Product Name 1   Product Name 2   Product name 3
1          A                B                C
2          E                F                D

The examples I can see in the forum deal with 3 variables. Mine has just 2 variables. I've tried reshape in my data. Doesn't seem to get the desired output.

mark
  • 1
  • 1
  • @akrun The examples I can see in the forum deal with 3 variables. Mine has just 2 variables. I've tried reshape in my data. Doesn't seem to get the desired output. – mark Mar 12 '18 at 10:00
  • 1
    You need a sequence `library(data.table); dcast(setDT(df1), Order_ID ~ paste0("Product_Name", rowid(Order_ID)), value.var = "Product_Name")` I am sure that there are dupes for this – akrun Mar 12 '18 at 10:01
  • 1
    akrun , Jogo: It worked! Thanks! – mark Mar 12 '18 at 10:08

0 Answers0