的功能我沒有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