Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of "I" in the R Language

Tags:

r

Naturally, I had little success searching Google for "R I", "I in R", and "R language I".

  • The R help says "Change the class of an object to indicate that it should be treated ‘as is’.".
  • My O'Reilly R book doesn't have an entry for it in its index.
  • My Cambridge book essentially says, about "I(logdist^2)": "ensures that is taken as the square, rather than as an interaction of logdist".

Can someone explain the "interaction" comment? Can someone explain why "logdist^2" wouldn't be interpreted in the traditional way?

like image 220
Dustin Oprea Avatar asked Jan 15 '15 04:01

Dustin Oprea


People also ask

What does I stand for in R?

I isolates or insulates the contents of I( ... ) from the gaze of R's formula parsing code. It allows the standard R operators to work as they would if you used them outside of a formula, rather than being treated as special formula operators.

What %>% means in R?

The pipe operator, written as %>% , has been a longstanding feature of the magrittr package for R. It takes the output of one function and passes it into another function as an argument. This allows us to link a sequence of analysis steps.

What does == mean in R?

== A boolean (meaning there are two possible values, true or false) operator which ensures that the values on the left side are the exact same as the values on the right, i.e., 5==5 would be true and 5==9 would be false.

What does dot mean in R?

It is just a variable name. R variables names can consist of alphanumerics and dot (.)


1 Answers

From p89 of R in a Nutshell

Caret(^) [is] Used to indicate crossing to a specific degree. For example:

y~(u+w)^2

is equivalent to

y~(u+w)*(u+w)

Identity function (I()) Used to indicate that the enclosed expression should be interpreted by it's arithmetic meaning. For example

a+b 

means that both a and b should be included in the formula. The formula:

I(a+b)  

means that "a plus b" should be included in the formula. See also ?AsIs()

like image 155
r.bot Avatar answered Oct 04 '22 03:10

r.bot