在R中将数据从长形重塑为半宽

在R中将数据从长形重塑为半宽,r,dataframe,reshape,R,Dataframe,Reshape,我有数据显示,每个参与者对9个对象中的每一个做出了3个判断(27个判断)。这9个对象在3x3设计(受试者内)中有所不同,因此有2个因素 我从ID+27数据列开始,我需要 身份证 2因素栏:绩效、情况 3个值列:成功、ProbAdmit、承认 我已经阅读了关于重塑()和熔化()以及铸造()的手册,但还没有弄清楚我需要做什么才能实现这一目标。这是我目前的进展,你可以从中看到我的实际数据 scsc3 <- read.csv("http://swift.cbdr.cmu.edu/data/SC

我有数据显示,每个参与者对9个对象中的每一个做出了3个判断(27个判断)。这9个对象在3x3设计(受试者内)中有所不同,因此有2个因素

我从ID+27数据列开始,我需要

  • 身份证
  • 2因素栏:绩效、情况
  • 3个值列:成功、ProbAdmit、承认
我已经阅读了关于重塑()和熔化()以及铸造()的手册,但还没有弄清楚我需要做什么才能实现这一目标。这是我目前的进展,你可以从中看到我的实际数据

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 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
...
思考dcast的一种方法是:“将”数据帧转换为宽格式 其中,行是参与者+绩效+情境的组合 列是
的不同可能值,即
允许、ProbAdmit、Success

value\u var='value'
表示应为每个“行-列”组合显示
value
列的条目。

太棒了!非常感谢。我还没有找到重塑2或dcast,但实际上,这个公式是我真正需要的。既然你这么做了,那当然看起来很明显。谢谢
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
...