R tidyr :: spread重复错误

时间:2016-05-19 18:14:34

标签: r dataframe reshape tidyr spread

我有以下数据:

ID        AGE SEX   RACE    COUNTRY VISITNUM    VSDTC   VSTESTCD    VSORRES
32320058    58  M   WHITE   UKRAINE 2   2016-04-28       DIABP          74
32320058    58  M   WHITE   UKRAINE 1   2016-04-21       HEIGHT        183
32320058    58  M   WHITE   UKRAINE 1   2016-04-21       SYSBP         116
32320058    58  M   WHITE   UKRAINE 2   2016-04-28       SYSBP         116
32320058    58  M   WHITE   UKRAINE 1   2016-04-21       WEIGHT        109
22080090    75  M   WHITE   MEXICO  1   2016-05-17       DIABP          81
22080090    75  M   WHITE   MEXICO  1   2016-05-17       HEIGHT        176
22080090    75  M   WHITE   MEXICO  1   2016-05-17       SYSBP         151

我想使用tidyr :: spread重新整形数据以获得以下输出:

ID AGE SEX  RACE    COUNTRY VISITNUM    VSDTC    DIABP SYSBP WEIGHT HEIGHT
32320058    58  M   WHITE   UKRAINE 2   2016-04-28   74   116   NA   NA
32320058    58  M   WHITE   UKRAINE 1   2016-04-21   NA   116   109   183
22080090    75  M   WHITE   MEXICO  1   2016-05-17   81   151   NA   176

我收到重复的错误,但我的数据中没有重复!

df1=spread(df,VSTESTCD,VSORRES)
  

错误:行的重复标识符(36282,36283),(59176,59177),(59179,59180)

1 个答案:

答案 0 :(得分:0)

我认为我理解你的问题

List