我并不感到惊讶,这个函数不起作用,但我不明白为什么。R:从包装函数传递参数到内部函数
computeMeans <- function(data,dv,fun) {
x <- with(data,aggregate(dv,
list(
method=method,
hypo=hypothesis,
pre.group=pre.group,
pre.smooth=pre.smooth
),
fun))
return(x)
}
computeMeans(df.basic,dprime,mean)
凡df.basic
与因素method
,hypothesis
等,和多个因变量的一个数据帧(我指定一个与dv
参数,dprime)。
我有多个因变量和几个数据帧都是相同的形式,所以我想写这个小函数来保持事情“简单”。我得到的错误是:
Error in aggregate(dv, list(method = method, hypo = hypothesis,
pre.group = pre.group, :
object 'dprime' not found
但dprime并在df.basic,这与with()
引用的存在。任何人都可以解释问题吗?谢谢!
编辑:这是R编程语言。 http://www.r-project.org/
的编程语言是这样吗? – Yogu 2012-07-30 21:27:32
R,http://www.r-project.org/(对不起,我以为我标记了它,感谢编辑)。 – 2012-07-30 21:28:12
给我们一个'df.basic'与'dput(head(df.basic))'' – nograpes 2012-07-30 21:41:11