这是我的代码:
df <- data.frame(RT=1:100,rep.sw=sample(c("sw","rep",100,replace=TRUE)))
sw.c <- sapply(data[c],function(df) with(df,na.omit(RT[rep.sw=="sw" & accuracy=="correct"])))
rep.c <- lapply(data[c],function(df) with(df,na.omit(RT[rep.sw=="rep" & accuracy=="correct"])))
sw.i <- lapply(data[i],function(df) with(df,na.omit(RT[rep.sw=="sw" & accuracy=="correct"])))
rep.i <- lapply(data[i],function(df) with(df,na.omit(RT[rep.sw=="rep" & accuracy=="correct"])))
我试图做的是:
df1 <- data.frame(x.c =sw.c)
df2 <- data.frame(x.c = rep.c)
do.call(rbind, lapply(list(df1, df2), function(x) {
setNames(x, sub("[.](.*)", "", names(x)))
}))
但是,它不允许我使用&#34; sw.c&#34;创建一个列。数据,说&#34; data.frame中的错误(&#39; 1,数据&#39; = c(blah,blah,blah)参数意味着不同的行数&#34; .sw.c的输出看起来像顺便说一下:
$`25.data`
[1] 2.1922950 1.1945300 1.1179349 1.4039009 1.0392207 0.7677145 0.8572351 1.0436683 1.0497756
[10] 0.9059841 1.3151253 1.3512195 1.1276046 0.8249148 0.7673886 0.8954072 1.0284413 1.0460338
[19] 0.6929680 0.7704327 0.7317035 0.8179957 0.8377674 0.6899160 1.0029663 0.9260365 0.9366969
[28] 1.1660660 0.8695714 0.9188830 1.1420787 3.0992697 1.0767574 0.7712549 1.2912305 0.8042407
[37] 1.2899323 0.7917820 1.2670543 0.6993181 1.3482055 0.7676718 0.9080072 2.0633686 0.7043455
[46] 0.8712553 0.8536238 0.7609185 0.7938010 0.8825289 0.9300739 0.7899570 0.9092923 0.7981818
[55] 0.6519451 0.9460687 1.4503399 0.9976737 1.4488700 0.9176023 0.8834117 0.6858608 0.8824608
[64] 0.6790607 1.1005604 0.9619213
attr(,"na.action")
[1] 1 3 5 6 7 9 11 12 14 16 18 20 22 24 26 27 29 30 32 34 36 38 40
[24] 42 44 46 48 50 52 54 55 57 59 60 62 64 66 67 69 70 72 74 76 78 79 81
[47] 84 86 88 90 91 93 94 96 97 99 101 102 103 105 107 109 110 112 113 115 116 118 119
[70] 120 122 123 125 127 129 131 133 135 137 139 141 143 145 147 149 150 152
attr(,"class")
[1] "omit"
$`26.data`
[1] 1.2973692 1.4937601 0.6676692 0.8910729 0.7900255 0.6622058 0.6486990 0.7381060 1.0959958
[10] 0.8516953 0.8388806 0.9495310 0.7419481 1.0736084 0.7752248 1.0160682 0.7187417 0.7616034
[19] 0.6000100 1.3476731 0.7360239 0.6063156 0.5680044 0.8791147 0.6686444 0.6713678 0.7468131
[28] 0.7287150 0.7421414 0.7271366 0.7213973 0.6053319 0.6671127 0.8374200 0.8190186 0.8847345
[37] 0.6273630 0.6597080 0.7839725 0.7182095 0.7133422 0.6242994 1.0470025 0.7489935 0.7237701
[46] 0.8116493 0.8295274 0.9101742 0.6048295 0.9070540 0.7777795 0.8547280 0.6238214 0.6458344
[55] 0.7474105 0.8862871 1.2171148 0.6424113 0.7724626 0.6475955 0.7030239 0.6568119 0.7620485
[64] 0.7075148 0.8609310 0.6532553 0.6515496 0.5968362 0.9849138 0.8352226 0.6893883 1.0399787
[73] 2.2893044 0.7794448 0.5832919 0.8968393 0.5587316 0.6783517 0.6963349 0.5586023 0.6106815
[82] 0.7239503 0.7016722 0.5622445 0.8449630 0.7690739 0.6046005 0.8027692 0.8153310 0.8576152
[91] 0.9175974 0.6883907 0.6942957 0.7024177 0.9694111 0.7410808 0.6595274 0.7453384 0.6093205
[100] 0.5062236 0.6364272 0.6296274 0.5389007 0.8316034
attr(,"na.action")
[1] 1 2 4 6 8 10 12 13 15 17 19 20 22 24 26 28 31 33 35 37 39 41 43
[24] 45 47 49 51 53 55 57 59 61 63 64 65 66 67 69 71 73 75 77 79 80 82 84
[47] 86 87 89 90 92 94 95 97 99 100 102 103 104 106 108 110 111 113 114 116 118 120 122
[70] 123 125 126 128 130 132 133 135 136 138 140 142 143 145 147 149 151 153 155 157 159 160 161
[93] 163 165 167 168 169 171 173 175 177 179 181 182 184 186 188 189 191 193 195 196 198 199 201
[116] 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 232 233 235 237 238
attr(,"class")
[1] "omit"
我认为问题在于它是一个列表,但我不确定如何转换它以便我只能提取反应时间(1.274635,0.746363值),并将它们放在整齐的列中!任何帮助将不胜感激!我爱你R社区!
答案 0 :(得分:0)
这就是诀窍:
df1.sw.c <- data.frame(RT = sw.c[[1]],I.C = rep(c("c"), each=82),sw.rep = rep(c("sw"),each=82))
df2.sw.c <- data.frame(RT = sw.c[[2]],I.C = rep(c("c"), each=117),sw.rep = rep(c("sw"),each=117))