I have a data frame with columns Users and Products.
> head(df1)
Users Product Code
[1,] "Alice" "Soap"
[2,] "Alice" "Shampoo"
[3,] "Alice" "Toothpaste"
[4,] "Bob" "Cup"
[5,] "Bob" "Spoon"
[6,] "Charlie" "Towel"
Is it possible to change this to
> head(df1)
Users Product Code
[1,] "Alice" "Soap, Shampoo, Toothpaste"
[2,] "Bob" "Cup, Spoon"
[3,] "Charlie" "Towel"
using any direct simple commands.
I currently do this by taking each user and checking what products he bought. Is there any simple way to do this?
item_set = list()
for(user_id in 1:length(user_code))
{
item_set[[user_id]] = products$product_code[products$customerID == user_id]
}