[R] What does this command "~" mean?

Dirk Eddelbuettel edd at debian.org
Sun Jan 29 05:45:19 CET 2006


On 28 January 2006 at 20:12, Michael wrote:
| I am reading books and tutorials about R.
| 
| I don't understand the following:
| 
| plot(salary~rank, data=salary)
| plot(Ozone~date, data=airquality)
| 
| I don't understand what does "~" here, 

If all else fails, you could consult the help system via either one of

	> help("~")
	> ?"~"

and within Emacs/ESS you even get to drop the quotes around ~.  In short, ~
stands between the left and right side of a model.  So what econometrics
books would call

	Y = X beta + epsilon

gets written here as

	Y ~ X

with the coefficient vector beta and errors epsilon being implied. 

| and how can plot() have a input
| argument called "data"... I have looked it up in "plot"'s help but I could
| not find about argument "data".

The 'R Intro' manual may be of help here.  In short

	> plot(Ozone~Day, data=airquality)

works because it tells plot that the columns Ozone and Day are part of the
data.frame airquality. The shorter plot(Ozone~Day) would fail unless you had
attach'ed airquality. Again, the 'R Intro' manual may help.

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
                                                  -- Thomas A. Edison




More information about the R-help mailing list