Miscellaneous Operators
Miscellaneous Operator are the mixed operators in R that simulate the printing of sequences and assignment of vectors, either left or right-handed.
%in% Operator
Checks if an element belongs to a list and returns a boolean value TRUE if the value is present else FALSE.
val <- 0.1
list1 <- c(TRUE, 0.1,"apple")
print (val %in% list1)
Output : TRUE
Checks for the value 0.1 in the specified list. It exists, therefore, prints TRUE.
%*% Operator
This operator is used to multiply a matrix with its transpose. Transpose of the matrix is obtained by interchanging the rows to columns and columns to rows. The number of columns of the first matrix must be equal to the number of rows of the second matrix. Multiplication of the matrix A with its transpose, B, produces a square matrix.
P_{r*r} " title="Rendered by QuickLaTeX.com" height="23" width="234" style="vertical-align: -4px;">
mat = matrix(c(1,2,3,4,5,6),nrow=2,ncol=3)
print (mat)
print( t(mat))
pro = mat %*% t(mat)
print(pro)
Input : Output :[,1] [,2] [,3] #original matrix of order 2x3 [1,] 1 3 5 [2,] 2 4 6 [,1] [,2] #transposed matrix of order 3x2 [1,] 1 2 [2,] 3 4 [3,] 5 6 [,1] [,2] #product matrix of order 2x2 [1,] 35 44 [2,] 44 56
The following R code illustrates the usage of all Miscellaneous Operators in R:
# R program to illustrate
# the use of Miscellaneous operators
mat <- matrix (1:4, nrow = 1, ncol = 4)
print("Matrix elements using : ")
print(mat)
product = mat %*% t(mat)
print("Product of matrices")
print(product,)
cat ("does 1 exist in prod matrix :", "1" %in% product)
Output
[1] "Matrix elements using : "
[,1] [,2] [,3] [,4]
[1,] 1 2 3 4
[1] "Product of matrices"
[,1]
[1,] 30
does 1 exist in prod matrix : FALSE
R Operators
Operators are the symbols directing the compiler to perform various kinds of operations between the operands. Operators simulate the various mathematical, logical, and decision operations performed on a set of Complex Numbers, Integers, and Numericals as input operands.