0
0
R Programmingprogramming~5 mins

Special operators (%in%, %*%) in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the %in% operator do in R?
The %in% operator checks if elements of one vector are present in another vector. It returns a logical vector of TRUE or FALSE values.
Click to reveal answer
beginner
How does the %*% operator work in R?
The %*% operator performs matrix multiplication between two matrices or vectors, following the rules of linear algebra.
Click to reveal answer
beginner
Example: What is the result of c(1, 2, 3) %in% c(2, 3, 4)?
The result is a logical vector: FALSE TRUE TRUE. It shows which elements of the first vector are found in the second.
Click to reveal answer
intermediate
Example: What is the output of matrix(c(1,2,3,4), nrow=2) %*% matrix(c(5,6,7,8), nrow=2)?
The output is a 2x2 matrix: [,1] [,2] [1,] 19 22 [2,] 43 50 This is the result of multiplying the two matrices using matrix multiplication rules.
Click to reveal answer
intermediate
Can %in% be used with data frames or lists?
Yes, %in% can be used to check if elements exist in vectors extracted from data frames or lists, but it works element-wise on vectors, not directly on data frames.
Click to reveal answer
What does the expression '3 %in% c(1, 2, 3, 4)' return in R?
ATRUE
BFALSE
C3
DError
Which operator is used for matrix multiplication in R?
A*
B%*%
C%in%
D%%
What is the output type of 'c(1,2,3) %in% c(2,3,4)'?
ANumeric vector
BMatrix
CLogical vector
DCharacter vector
If A is a 2x3 matrix and B is a 3x2 matrix, what does A %*% B produce?
AError
BA 3x3 matrix
CA 2x3 matrix
DA 2x2 matrix
Can %in% be used to check if a value is in a list directly?
ANo, it only works on vectors
BYes, it works directly on lists
CYes, but only for numeric lists
DNo, it only works on matrices
Explain how the %in% operator works and give a simple example.
Think about checking if items are inside a shopping list.
You got /3 concepts.
    Describe the purpose of the %*% operator and what kind of data it works with.
    Imagine multiplying two tables of numbers to get a new table.
    You got /3 concepts.