的功能我没有R中很多经验,所以纠正我,如果我做一个基本错误:问题传递数据中的R
我有一个函数:
ctree_result <- function(yval, training, testing) {
print(yval)
trained_tree <- ctree(formula = ordered(yval) ~ ., subset=training, data=ealls)
print("here")
tree_cor <- cor(yval[testing], as.numeric(predict(trained_tree, ealls[testing])))
c_mat <- rbind(yval[testing], as.numeric(predict(trained_tree, ealls[testing])))
tree_kappa <- cohen.kappa(t(c_mat))
return(c(tree_cor, tree_kappa))
}
当我称之为(与任何数据,但例如):
ctree_result(emean.data$mean.Shape, 1:70, 71:80)
我得到错误Error in factor(x, ..., ordered = TRUE) : object 'yval' not found
。但是,第一个打印语句有效,矢量打印出来。第二个打印语句从不运行。 yval
似乎不会传递给ctree。
yval <- emean.data$mean.Shape
sauc_tree = ctree(formula = ordered(yval) ~ . , data=ealls)
,没有任何问题:
我可以为手动运行ctree
功能。 ealls
和emean.data
是我之前定义的全局数据集。
emean.data $ mean.Shape包含什么? – Shane 2010-12-17 19:54:30
80个整数的向量。 – tkerwin 2010-12-17 19:56:58
查看我的更新。由于懒惰的评估,你可能会遇到问题。你传递的是表达式'emean.data $ mean.Shape',而不是它的值。你可能需要首先用'eval'函数来评估它。 – Shane 2010-12-17 19:59:36