What is the meaning of ~ in aggregate?

前端 未结 3 1961
滥情空心
滥情空心 2021-01-01 08:23
x <- iris[,1:4]
names(x) <- c(\"x1\",\"x2\",\"x3\",\"x4\")
aggregate(x1+x2+x3+x4~x1,FUN=sum,data=x)

Here is the output ,i wonder
1. What

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 08:53

    The tilde operator creates a symbolic formula. Here's an excerpt from a blog post that explains it better than I could:

    f = price ~ carat

    [...]

    We start by creating the formula f using the strange looking tilde operator. That tells the R interpreter that we're defining a symbolic formula, rather than an expression to be evaluated immediately. So, our definition of formula f says, "price is a function of carat".

    The manual page on formulas has more to say about the tilde operator.

提交回复
热议问题