0

I have a data set with three columns

df <- data.frame(user = c('user1', 'user2', 'user3', 'user4'), items = c("1537,9864,8904", "2467", "3589,9074", "4406,8730,0937,0853"), number = c("1,1,2", "2", "2,2", "1,1,3,2"))
df

enter image description here

In this case, the second column means the names of the goods, in the third column means how much of each product was purchased.

I want to divide the columns in such a way as to get a dataset where the first column will denote the user, and the remaining columns will contain information about how many and what goods were ordered

df2  <- data.frame(user = c("user1", "user1", "user1", "user2", "user3", "user3", "user4", "user4", "user4", "user4"), items = c("1537", "9864", "8904", "2467", "3589" ,"9074", "4406", "8730", "0937", "0853"), number = c("1", "1", "2", "2", "2", "2", "1", "1", "3", "2"))
df2

enter image description here

Please help me how to divide the second and third columns so that they take this form

Milena
  • 1

0 Answers0