Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of . in aggregate function? [duplicate]

Tags:

r

Possible Duplicate:
What does the period mean in the following R excerpt?

in the aggregate help file:

Dot notation:  
aggregate(. ~ Species, data = iris, mean)  
aggregate(len ~ ., data = ToothGrowth, mean)  

What is meaning of . here?

like image 381
Bqsj Sjbq Avatar asked Dec 30 '12 01:12

Bqsj Sjbq


2 Answers

It means "all other variables." That is, those variables of the data which are not otherwise present in the formula.

In the first expression, these are Sepal.Length, Sepal.Width, Petal.Length, Petal.Width as can be seen by running the command:

aggregate(. ~ Species, data = iris, mean)  
     Species Sepal.Length Sepal.Width Petal.Length Petal.Width
1     setosa        5.006       3.428        1.462       0.246
2 versicolor        5.936       2.770        4.260       1.326
3  virginica        6.588       2.974        5.552       2.026

This statement is equivalent:

aggregate(cbind(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) ~ Species, data = iris, mean)  
like image 123
Matthew Lundberg Avatar answered Oct 10 '22 04:10

Matthew Lundberg


From ?formula

There are two special interpretations of ‘.’ in a formula. The usual one is in the context of a ‘data’ argument of model fitting functions and means ‘all columns not otherwise in the formula’: see ‘terms.formula’. In the context of ‘update.formula’, only, it means ‘what was previously in this part of the formula’.

like image 24
GSee Avatar answered Oct 10 '22 04:10

GSee