This set of 30 multiple-choice questions focuses on the fundamental operations and functions in R. Learn how to work with arithmetic, logical, relational operators, and use both simple and built-in functions efficiently.
Chapter: Basic Operations and Functions in R – MCQs
1. Arithmetic, Logical, and Relational Operators (10 Questions)
Which of the following is the correct operator for exponentiation in R? a) ^ b) ** c) exp() d) pow()
What is the output of the following expression: 5 %% 3 in R? a) 1 b) 2 c) 3 d) 5
Which operator is used for checking equality in R? a) == b) = c) === d) !==
What is the result of the following R expression: TRUE & FALSE? a) TRUE b) FALSE c) NA d) Error
In R, which operator is used to combine logical conditions in an OR operation? a) & b) | c) == d) &&
Which of the following is used for performing a relational operation in R? a) != b) == c) < d) All of the above
Which of the following is an example of a logical operator in R? a) && b) <= c) + d) *
What does the expression x > 10 return if x = 5 in R? a) TRUE b) FALSE c) NA d) Error
Which operator is used to test if two values are not equal in R? a) == b) != c) = d) <>
What does the == operator return when comparing two different data types in R (e.g., a number and a string)? a) TRUE b) FALSE c) NA d) Error
2. Writing Simple Functions (10 Questions)
How do you define a function in R? a) function(x) {} b) def function(x) {} c) func function(x) {} d) function[]
Which of the following syntax is used to return a value from a function in R? a) return(value) b) value c) value = return() d) output(value)
What is the default argument for sum() function in R? a) na.rm = FALSE b) na.rm = TRUE c) na = FALSE d) ignore.na = FALSE
In R, which keyword is used to pass an argument to a function? a) input b) argument c) var d) x
What is the correct way to call a function with arguments in R? a) function(x, y) b) function(x = 10, y = 5) c) function(x, y = 5) d) function(10, 5)
How do you pass a default argument in an R function? a) function(x = 10) {} b) function(10 = x) c) function(x, default = 10) d) function(10)
Which of the following is the correct way to define a function with no arguments in R? a) function() {} b) function(x) {} c) function(x = NULL) d) def function() {}
What will happen if you attempt to call a function without required arguments in R? a) The function will run without arguments b) The function will return NULL c) An error will be thrown d) The function will return an empty value
How do you assign a function to a variable in R? a) myFunc <- function() {} b) myFunc = function() {} c) function() <- myFunc d) assign(function, myFunc)
In R, which function is used to check if an object is a function? a) is.function() b) is.fun() c) typeof() d) is_callable()
3. Using Built-In Functions (10 Questions)
Which of the following is a built-in function in R for calculating the mean of a numeric vector? a) average() b) mean() c) avg() d) sum()
What is the output of length(c(1, 2, 3)) in R? a) 1 b) 2 c) 3 d) 4
Which function in R is used to generate random numbers? a) rand() b) random() c) rnorm() d) runif()
Which of the following functions is used to find the maximum value in a numeric vector in R? a) max() b) maximum() c) findMax() d) maxValue()
What function in R is used to get the structure of an object? a) getStructure() b) str() c) structure() d) type()
Which of the following R functions is used to check if a value is NA (missing)? a) is.na() b) check.na() c) missing() d) findNA()
What does the table() function in R do? a) Creates a frequency table of values b) Creates a table of column names c) Finds the sum of elements in a table d) Converts data into a table format
Which R function is used to sort a vector or data frame? a) sort() b) order() c) arrange() d) rank()
What does the unique() function do in R? a) Removes duplicates from a vector b) Returns a vector of unique values c) Sorts values in ascending order d) All of the above
Which of the following R functions is used to combine vectors or lists? a) combine() b) c() c) merge() d) bind()