anonymus
anonymus

Reputation: 23

Shaping or structuring the data in R for Market Basket Analysis

I have a dataset with columns like Order ID, Productname and others

Order ID.   Productname
121.         Shirt
122.         Tie
121.         Socks
122.         Belt
122.         Shirt

I want the data to be shaped like below to perform the Market Basket Analysis in R

Order Id.   Productname
121          Shirt,Socks
122.         Tie,Belt,Shirt

I have come across different ways of doing it some using aggregate function or summarize function.But I am not able to get the output

Please share what functions or method to do this

THANKS IN ADVANCE

Upvotes: 0

Views: 85

Answers (1)

akrun
akrun

Reputation: 887118

An option with base R

aggregate(Productname ~ ., df1, FUN = toString)
#  Order ID.      Productname
#1       121     Shirt, Socks
#2       122 Tie, Belt, Shirt

Upvotes: 1

Related Questions