在R编程语言中使用〜(波浪号) [英] Use of ~ (tilde) in R programming Language
问题描述
我在有关回归建模的教程中看到以下命令:
I saw in a tutorial about regression modeling the following command :
myFormula <- Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
此命令的作用是什么?~
(波浪号)在命令中的作用是什么?
What exactly does this command do, and what is the role of ~
(tilde) in the command?
推荐答案
<-
右侧的内容是.
The thing on the right of <-
is a formula
object. It is often used to denote a statistical model, where the thing on the left of the ~
is the response and the things on the right of the ~
are the explanatory variables. So in English you'd say something like "Species depends on Sepal Length, Sepal Width, Petal Length and Petal Width".
该行的myFormula <-
部分将公式存储在名为myFormula
的对象中,因此您可以在R代码的其他部分中使用它.
The myFormula <-
part of that line stores the formula in an object called myFormula
so you can use it in other parts of your R code.
R中公式对象的其他常见用法
lattice
软件包使用它们来指定要绘制的变量.
ggplot2
软件包使用它们来指定用于绘图的面板.
dplyr
软件包将它们用于非标准评估.
The lattice
package uses them to specify the variables to plot.
The ggplot2
package uses them to specify panels for plotting.
The dplyr
package uses them for non-standard evaulation.
这篇关于在R编程语言中使用〜(波浪号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!