I have a dataset that looks like the following:
name ingredient allergic
prod1 ing1 yes
prod1 ing2 yes
prod2 ing1 no
prod2 ing3 no
prod3 ing3 yes
I want to convert the ingredient variable to dummies and format my data such that it looks like:
name ing1 ing2 ing3 allergic
prod1 1 1 0 yes
prod2 1 0 1 no
prod3 0 0 1 yes
Does any one know how I can go about doing this? I was able to convert my variables to dummies using
model.matrix(allergic ~ ingredient, data)
But I don't think it is doing what I want it to. Any help would be greatly appreciated!