将数据从R的长整形更改为半宽

问题描述

| 我有数据,其中每个参与者对9个对象中的每个对象做出3个判断(27个判断)。 9个对象采用3x3设计(在主题内)不同,因此有2个因素。 我从ID + 27数据列开始,我需要 ID 2个因子列:性能,情况 3个值列:成功,准入,准入 我已经阅读了有关reshape(),melt()和cast()的手册,但还没有弄清楚我需要做些什么才能实现它。这是我当前的进度,您可以从中查看我的实际数据。
scsc3 <- read.csv(\"http://swift.cbdr.cmu.edu/data/SCSC3-2006-10-10.csv\")
library(reshape)
scsc3.long <- melt(scsc3,id=\"Participant\")
scsc3.long <- cbind(scsc3.long,colsplit(scsc3.long$variable,split=\"[.]\",names=c(\"Item\",\"Candidate\",\"Performance\",\"Situation\")))
scsc3.long$variable <- NULL
scsc3.long$Candidate <- NULL
上面的代码我有了:
Participant  value  Item      Performance  Situation
4001         5.0    Success   GL           IL
4001         60     ProbAdmit GL           IL
4001         1      Admit     GL           IL
4002         ....
我需要的是这样的数据框
Participant Performance  Situation SuccessValue ProbAdmitValue AdmitValue
4001        GL           IL        5.0          60             1
...
谢谢!     

解决方法

        尝试这个:
require(reshape2)
> dcast(scsc3.long,Participant + Performance + Situation ~ Item,value_var = \'value\' )

  Participant Performance Situation Admit ProbAdmit Success
1        4001          GH        IH     1       100       7
2        4001          GH        IL     1        50       5
3        4001          GH        IM     1        60       5
4        4001          GL        IH     0        40       3
5        4001          GL        IL     0         0       2
6        4001          GL        IM     0        40       4
...
思考“ 4”在做什么的一种方法是:“将”数据帧“投射”为宽格式 行是
Participant + Performance + Situation
和 列是
Item
的不同可能值,即values7ѭ。 ѭ8表示对于每个“行-列”组合,应显示“ 9”列的条目。