Meaning of ~. (tilde dot) argument?

前端 未结 1 1990
情话喂你
情话喂你 2020-11-27 02:55

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

For example plot(~.,xyz..)

I have seen this argument used several times in various con

相关标签:
1条回答
  • 2020-11-27 03:36

    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.

    0 讨论(0)
提交回复
热议问题