将数据帧或事件转换为频率

时间:2018-05-22 01:26:47

标签: r reshape melt

testData <- data.frame("player" = c(1,2,1,2,2,3,3,2,3,1),
                    "event" = c(rep("shot",3),rep("pass",5),rep("score",2)))

testData
#   player event
#1       1  shot
#2       2  shot
#3       1  shot
#4       2  pass
#5       2  pass
#6       3  pass
#7       3  pass
#8       2  pass
#9       3 score
#10      1 score


desiredResult

#  player shots passes scores
#1      1     2      0      1
#2      2     1      3      0
#3      3     0      2      1

0 个答案:

没有答案