5

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?

Community
  • 1
  • 1
Bqsj Sjbq
  • 1,231
  • 1
  • 12
  • 9

2 Answers2

7

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)  
Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
  • Note though that the use of cbind requires all arguments to be of the same type, so you couldn't do (for example) `aggregate(len ~ cbind(supp,dose),data=ToothGrowth,mean)` - you have to do `aggregate(len ~ .,data=ToothGrowth,mean)` or `aggregate(len ~ supp+dose,data=ToothGrowth,mean)` – Scott C Wilson Feb 13 '16 at 01:43
6

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’.

GSee
  • 48,880
  • 13
  • 125
  • 145