首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R- as.formula()不使用ctree {party}?

R- as.formula()不使用ctree {party}?
EN

Stack Overflow用户
提问于 2015-09-10 12:54:30
回答 1查看 1.4K关注 0票数 2

当我试图从Error: $ operator not defined for this S4 class运行ctree时,只有当公式被写为使用as.formula()转换的字符串时,才会得到as.formula()

下面的例子是:

代码语言:javascript
复制
#This works fine :
y <- ctree(formula = quotation ~ minute + temp, data=test[[1]], controls = ctree_control(mincriterion = 0.99))

#While this doesn't :
x <- "ctree(formula = quotation ~ minute + temp, data=test[[1]], controls = ctree_control(mincriterion = 0.99))"

y <- as.formula(x)
Error: $ operator not defined for this S4 class

我的最终目的是创建一个通过列表test来创建多个树的函数。

知道吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-10 14:05:34

ctree是一个函数,而不是公式。formula是由函数'~' (tilde)产生的对象的类。您可以从help('~')help('formula')了解有关公式的更多信息。

使用as.formula最常用的方法是将表示公式语法的字符串转换为类公式的对象。有点像as.formula('y ~ x')。另外,检查class(as.formula(y~x))

在您的示例中,您将表示函数ctree的字符串保存为变量x。函数ctree只包含表示公式语法(quotation ~ minute + temp)的字符串,但不能强迫它使用公式(它不代表公式,它只包含公式语法字符串),因为它不遵循公式语法。

如果您想要从文本中执行函数,则需要使用eval(parse(text = x)),尽管不鼓励这种技术。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32502507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档