heavy rocker dude heavy rocker dude - 3 months ago 8
R Question

What do the %op% operators in mean in R? For example "%in%"

I tried to do this simple search but couldn't find anything on the percent (

%
) symbol in R. What does
%in%
mean in the following code?

time(x) %in% time(y)


x
and
y
are matrices.

How do I look up help on
%in%
and similar functions that follow the
%stuff%
pattern, as I cannot locate the help file?

Related questions:

What does eg %+% do? in R

The R %*% operator

What does %*% mean in R

https://stackoverflow.com/questions/23091654/what-does-it-mean-when-something-is-between-two-percent-signs-in-r

What does %||% do in R?

What does %>% mean in R

Answer

Put quotes around it to find the help page. Either of these work

> help("%in%")
> ?"%in%"

Once you get to the help page, you'll see that

‘%in%’ is currently defined as

‘"%in%" <- function(x, table) match(x, table, nomatch = 0) > 0’


Since time is a generic, I don't know what time(X2) returns without knowing what X2 is. But, %in% tells you which items from the left hand side are also in the right hand side.

> c(1:5) %in% c(3:8)
[1] FALSE FALSE  TRUE  TRUE  TRUE

See also, intersect

> intersect(c(1:5), c(3:8))
[1] 3 4 5
Comments