“数据框的标准公式接口”是什么? R 中的意思?
aggregate
的文档指出:
“aggregate.formula”是“aggregate.data.frame”的标准公式接口。
我是R新手,不明白这是什么意思。请解释一下!
谢谢!
乌里
The documentation for aggregate
states:
‘aggregate.formula’ is a standard formula interface to ‘aggregate.data.frame’.
I am new to R, and I don't understand what this means. Please explain!
Thanks!
Uri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跳转到
help(aggregate)
示例部分的中间,您将看到:对
aggregate()
的四种不同调用,全部使用公式 界面。上面你引用的内容与整个 R 中使用的方法分派机制有关。考虑第一个例子:
所以聚合分派它的第一个参数(类
formula
)。 R 中公式的解析方式通常围绕 model.matrix,我认为这里也发生了类似的情况,并且最终由aggregate.data.frame 执行等效的调用,使用第二个参数chickwts
,一个data.frame
。你问的不是最简单的初学者问题,我建议你仔细阅读一些文档,如果你手头有一本像样的 R 书,我建议你仔细阅读。 (其他SO问题给出了接下来要读什么的建议。)
编辑:我不得不挖掘一点,因为
aggregate.formula()
没有从导出stats
命名空间,但您可以通过在提示符处输入stats:::aggregate.formula
来查看它 - 然后清楚地表明它实际上会分派到aggregate.data.frame():
Jump to the middle of the examples section of
help(aggregate)
and you will see this:Four different calls to
aggregate()
, all using the formula interface. The way it is written above in what you quote has to do with method dispatching mechanism used throughout R.Consider the first example:
so aggregate dispatches on it first argument (of class
formula
). The way a formula gets resolved in R typically revolves around amodel.matrix
, I presume something similar happens here and an equivalent call is eventually execucted byaggregate.data.frame
, using the second argumentchickwts
, adata.frame
.What you asked isn't the easiest beginner question, I'd recommend a good thorough look at some of the documentation and a decent R book if you have one handy. (And other SO questions give recommendation as to what to read next.)
Edit: I had to dig a little as
aggregate.formula()
is not exported fromstats
namespace, but you can look at it by typingstats:::aggregate.formula
at the prompt -- which then clearly shows that it does, in fact, dispatch toaggregate.data.frame()
: