Error: $ operator not defined for this S4 class

Error: $ operator not defined for this S4 class

我正在尝试制作公式,但出现错误:

$ operator not defined for this S4 class with R.

首先,什么是S4class?我做错了什么?

代码如下:

as.formula("ctree(d$sex ~ d$ahe , data = d)")

如果要复现,数据集(CSV文件)davailable here

您在此处 as.formula 输入错误。只有 d$sex ~ d$ahe 应该是一个公式,所以:

ctree(as.formula("d$sex ~ d$ahe"))

或者:

ctree(as.formula("sex ~ ahe"), data = d)