答案 0 :(得分:1)
就像那样:
library(reshape2)
df <- data.frame(Name=c("Tom", "Tom", "Hardy", "Hardy"),
Drug=c("drug1", "drug2", "drug1", "drug3"),
Value=c(20,10,30,40))
dcast(df,Name~Drug, fill = 0 )
Name drug1 drug2 drug3
1 Hardy 30 0 40
2 Tom 20 10 0