在没有“timevar”的情况下,将数据从长格式转到宽格式
Name MedName Name1 atenolol 25mg Name1 aspirin 81mg Name1 sildenafil 100mg Name2 atenolol 50mg Name2 enalapril 20mg
Name medication1 medication2 medication3 Name1 atenolol 25mg aspirin 81mg sildenafil 100mg Name2 atenolol 50mg enalapril 20mg NA
dcast(dataframe, Name ~ MedName, value.var='MedName')
Name atenolol 25mg aspirin 81mg Name1 1 1Name2 0 0
dcast(dataset, Name ~ variable)
Name MedName Name1 3name2 2
idvar="Name"
timevar="variable"
米脂