我有一些代码,其聚合数据:当我使用eval与骨料,我失去了变量名
pivot.present.RT <- with(
subset(correct.data, relevantTarget == 1),
aggregate(
data.frame(RT = RT),
list(
identifier = identifier,
set.size = relevantSS,
stimulus = stimulus
),
mean
)
)
我想通过指定不同的列名取的地方,使这种更灵活“relevantSS”。我以为我可以用EVAL做到这一点:
set.size.options <- c("relevantSS","irrelevantSS")
pivot.present.RT <- with(
subset(correct.data, relevantTarget == 1),
aggregate(
data.frame(RT = RT),
list(
identifier = identifier,
eval(parse(text = paste("set.size = ", set.size.options[relevant.index]))),
stimulus = stimulus
),
mean
)
)
然而,当我运行代码的第二位,而它并正确汇总数据,我失去了变量名“set.size”。如果我叫海峡,我得到的输出是这样的:
'data.frame': 48 obs. of 4 variables:
$ identifier: Factor w/ 9 levels "aks","ejr","ejr3",..: 1 2 4 5 6 7 8 9 1 2 ...
$ Group.2 : int 4 4 4 4 4 4 4 4 8 8 ...
$ stimulus : Factor w/ 2 levels "moving","stationary": 1 1 1 1 1 1 1 1 1 1 ...
$ RT : num 1161 1026 1257 1264 1324 ...
如果我运行的原代码,它正确地识别第二个变量是“set.size”。
任何想法我在这里失踪?
啊,是的,这工作插入内容。谢谢! –