I do not know if my title for the question makes sense. I am trying to write a code that replace the count with the name of the columns. For example if the count of an observation has 2, the Id of that observation becomes 2 with the name of the column instead of the count. The tables below shows what I want if my explanation does not make sense.
This is my table (code):
df <- structure(list(ID = c("P40", "P41", "P43"), 
                     Fruit = c(2, 2, 1),
                     Snack = c(2, 1, 1)),
                class = "data.frame", row.names = c(NA, -3L))
Table:
ID    Fruit Snack
P40     2     2
P41     2     1
P43     1     1
This is what i want to achieve:
 ID  Items 
P40  Fruit    
P40  Fruit
P40  Snack
P40  Snack
P41  Fruit
P41  Fruit
P41  Snack
P43  Fruit         
P43  Snack
 
     
     
     
    