Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of ~. (tilde dot) argument?

Tags:

syntax

r

What is the meaning of the ~. argument in R?

For example plot(~.,xyz..)

I have seen this argument used several times in various contexts and since it is difficult to meaningfully search for symbols on google, I have met little success.

like image 278
Info5ek Avatar asked Nov 19 '12 00:11

Info5ek


People also ask

What does tilde dot mean in R?

Tilde operator is used to define the relationship between dependent variable and independent variables in a statistical model formula. The variable on the left-hand side of tilde operator is the dependent variable and the variable(s) on the right-hand side of tilde operator is/are called the independent variable(s).

How do you make a tilde in R?

AltGr + ^ will give you a tilde ~~~~ on a Linux system with an Italian keyboard, which is what you said you were using in the comments. Show activity on this post. You could use this variable when you need tilde in text. Alternately, you could just type tilde and copy and paste the character.


1 Answers

This is a formula, in a shorthand notation. Try this:

plot( mpg ~ cyl, data= mtcars ) 

The left hand is the dependent variable, the right hand is the independent variable. Much like y = bx + c means that y ~ x.

Formulas are one of the corner stones of R, and you will need to understand them to use R efficiently. Most frequently, formulas are used in modeling of all sorts, for example you can do basic linear regression with

lm( mpg ~ wt, data= mtcars ) 

...to see how mileage per gallon depend on weight. Take a look at ?formula for some more explanations.

The dot means "any columns from data that are otherwise not used". Google for "R formulas" to get more information.

like image 154
January Avatar answered Sep 24 '22 01:09

January