MCQs on Basic Operations and Functions | R

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)

  1. Which of the following is the correct operator for exponentiation in R?
    a) ^
    b) **
    c) exp()
    d) pow()
  2. What is the output of the following expression: 5 %% 3 in R?
    a) 1
    b) 2
    c) 3
    d) 5
  3. Which operator is used for checking equality in R?
    a) ==
    b) =
    c) ===
    d) !==
  4. What is the result of the following R expression: TRUE & FALSE?
    a) TRUE
    b) FALSE
    c) NA
    d) Error
  5. In R, which operator is used to combine logical conditions in an OR operation?
    a) &
    b) |
    c) ==
    d) &&
  6. Which of the following is used for performing a relational operation in R?
    a) !=
    b) ==
    c) <
    d) All of the above
  7. Which of the following is an example of a logical operator in R?
    a) &&
    b) <=
    c) +
    d) *
  8. What does the expression x > 10 return if x = 5 in R?
    a) TRUE
    b) FALSE
    c) NA
    d) Error
  9. Which operator is used to test if two values are not equal in R?
    a) ==
    b) !=
    c) =
    d) <>
  10. 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)

  1. How do you define a function in R?
    a) function(x) {}
    b) def function(x) {}
    c) func function(x) {}
    d) function[]
  2. 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)
  3. 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
  4. In R, which keyword is used to pass an argument to a function?
    a) input
    b) argument
    c) var
    d) x
  5. 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)
  6. 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)
  7. 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() {}
  8. 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
  9. How do you assign a function to a variable in R?
    a) myFunc <- function() {}
    b) myFunc = function() {}
    c) function() <- myFunc
    d) assign(function, myFunc)
  10. 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)

  1. 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()
  2. What is the output of length(c(1, 2, 3)) in R?
    a) 1
    b) 2
    c) 3
    d) 4
  3. Which function in R is used to generate random numbers?
    a) rand()
    b) random()
    c) rnorm()
    d) runif()
  4. 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()
  5. What function in R is used to get the structure of an object?
    a) getStructure()
    b) str()
    c) structure()
    d) type()
  6. 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()
  7. 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
  8. Which R function is used to sort a vector or data frame?
    a) sort()
    b) order()
    c) arrange()
    d) rank()
  9. 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
  10. Which of the following R functions is used to combine vectors or lists?
    a) combine()
    b) c()
    c) merge()
    d) bind()

Answers

QNoAnswer (Option with the text)
1a) ^
2a) 1
3a) ==
4b) FALSE
5b) `
6d) All of the above
7a) &&
8b) FALSE
9b) !=
10b) FALSE
11a) function(x) {}
12a) return(value)
13a) na.rm = FALSE
14d) x
15b) function(x = 10, y = 5)
16a) function(x = 10) {}
17a) function() {}
18c) An error will be thrown
19a) myFunc <- function() {}
20a) is.function()
21b) mean()
22c) 3
23d) runif()
24a) max()
25b) str()
26a) is.na()
27a) Creates a frequency table of values
28a) sort()
29d) All of the above
30b) c()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top