I have a data frame as follows:
Name MedName
Name1 atenolol 25mg
Name1 aspirin 81mg
Name1 sildenafil 100mg
Name2 atenolol 50mg
Name2 enalapril 20mg
I would like to get the data in the below format:
Name medication1 medication2 medication3
Name1 atenolol 25mg aspirin 81mg sildenafil 100mg
Name2 atenolol 50mg enalapril 20mg NA
When I tried using dcast(dataframe, Name ~ MedName, value.var='MedName')
I just get a bunch of columns that are flags of the medication names (values that get transposed are 1 or 0) example:
Name atenolol 25mg aspirin 81mg
Name1 1 1
Name2 0 0
How do I reshape using the dcast function