What is this? I can't find help by using ?
. (Sorry for being dumb)
> 1%*%1
[,1]
[1,] 1
> 10%*%10
[,1]
[1,] 100
> c(1:2)%*%c(1:2)
[,1]
[1,] 5
It is called the multiplication operator. The %*% operator is a special kind of multiplication operator. It is used in the multiplication of matrices in R.
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. R language is rich in built-in operators and provides following types of operators.
& and && indicate logical AND and | and || indicate logical OR. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
The Inequality Operator != For example, the sentence "hello" != "goodbye" would read as: “hello” is not equal to “goodbye”. Because this statement is correct, R will output TRUE . The inequality operator can also be used for numerics, logicals, and other R objects.
R has several operators to perform tasks including arithmetic, logical and bitwise operations. In this article, you will learn about different R operators with the help of examples. R has many operators to carry out different mathematical and logical operations.
The %in% operator in R allows you to determine whether or not an element belongs to a vector or data frame. This tutorial provides three examples of how to use this function in different scenarios.
For example, some of the commonly used arrive maniac operators are addition operators represented by ‘+’ symbol for adding two vector values in R, ‘=’ or ‘<- ‘ is the assignment operator used to assign values the variable. The R operators help to develop standardized program logic. R Operators have many built-in operators.
Arithmetic operators are used with numeric values to perform common mathematical operations: Note: <<- is a global assigner. You will learn more about this in the Global Variable chapter. It is also possible to turn the direction of the assignment operator. Element-wise Logical AND operator.
It's a matrix multiplication operator!
From the documentation:
Description:
Multiplies two matrices, if they are conformable. If one argument is a vector, it will be promoted to either a row or column matrix to make the two arguments conformable. If both are vectors of the same length, it will return the inner product (as a matrix).
Usage:
x %*% y
Arguments:
x
,y
numeric or complex matrices or vectors
> c(1,2,3) %*% c(4,5,6)
[,1]
[1,] 32
> c(1,2,3) * c(4,5,6)
[1] 4 10 18
Like MadSeb said, it is the matrix multiplication operator. If you give it two vectors, it will coerce them to (logical) 1-row & a 1-col matrix and multiply them.
It is also the inner (or dot) product between two vectors and finds wide usage in linear algebra, computational geometry and a host of other applications.
http://en.wikipedia.org/wiki/Dot_product
BTW, the vectors have to be in the same space (same number of dimensions)
> c(1,2,3) %*% c(4,5,6,7)
Error in c(1, 2, 3) %*% c(4, 5, 6, 7) : non-conformable arguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With