Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of %o% in R

I encountered the following in R:

x=x+y%o%c(1.5,1.5)

I am wondering what is the meaning of %o% here. I tried googling but didn't have much luck

like image 733
hi15 Avatar asked Mar 11 '15 17:03

hi15


People also ask

What does '$' mean in R?

Generally speaking, the $ operator is used to extract or subset a specific part of a data object in R. For instance, this can be a data frame object or a list. In this example, I'll explain how to extract the values in a data frame columns using the $ operator.

What does %>% do in R?

1 Answer. %>% is called the forward pipe operator in R. It provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression.

What does percent mean in R?

The %.% operator in dplyr allows one to put functions together without lots of nested parentheses. The flanking percent signs are R's way of denoting infix operators; you might have used %in% which corresponds to the match function or %*% which is matrix multiplication.


1 Answers

There are a number of shortcuts in R that use the %...% notation. %o% is the outer product of arrays

> 1:3 %o% 1:3
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
[3,]    3    6    9

There are a number of others, my most used is %in%:

3 %in% c(1,2,3,4) #TRUE
5 %in% c(1,2,3,4) #FALSE
3.4 %in% c(1,2,3,4) #FALSE

There are a few others, I don't know them all off the top of my head. But when you encounter them, you can check for documentation by using backticks around the %o% like ?`%o%`, or quotes ?'%o%' (or ?"%o%").

They are obviously difficult to google because of the percent sign.

like image 84
Señor O Avatar answered Sep 20 '22 10:09

Señor O