📊

R MCQ

Test your R knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

100 Questions 40 Beginner 40 Intermediate 20 Advanced
1

What is R primarily used for?

2

Which operator is most commonly used for assignment in R?

3

How do you print the value of a variable x to the console?

4

Which function returns the number of elements in a vector?

5

How do you create a vector containing the numbers 1, 2, and 3?

6

Which data structure in R can hold elements of different types (e.g., numbers, strings, logical values) together?

7

What function is used to check the class/type of an object?

8

How do you create a comment in R?

9

Which function reads a CSV file into a data frame?

10

What does NA represent in R?

11

Which symbol is used to access a column in a data frame by name?

12

How do you create a sequence of numbers from 1 to 10?

13

What is the function to install a package in R?

14

Which function loads an installed package into the current session?

15

What is the result of TRUE + TRUE in R?

16

Which function returns summary statistics (min, max, mean, quartiles) for a numeric vector?

17

How do you create a function in R that adds two numbers?

18

What does the "str()" function do when applied to an object?

19

Which function checks if a value is missing (NA)?

20

How do you create a matrix with 2 rows and 3 columns from the numbers 1 through 6?

21

What is the result of "5 %% 2" in R?

22

Which function is used to remove an object from the current R environment?

23

How do you select the first element of a vector named v?

24

Which function converts a character string to numeric?

25

What does the "if-else" structure look like in R for checking if x is greater than 10?

26

Which loop construct repeats a block of code for each element in a vector?

27

What is the default value of an uninitialized logical comparison result when comparing NA to anything, e.g. "NA == 5"?

28

Which function combines two data frames by stacking their rows?

29

What is the correct way to get help/documentation for the function "mean" in R?

30

Which built-in constant represents an infinite value in R?

31

How do you create a factor variable from a character vector?

32

What does the function "nrow(df)" return for a data frame df?

33

Which operator is used for logical AND in R when working with single values in an if condition?

34

Which function generates a sequence of random numbers from a normal distribution?

35

What is the working directory in R and which function returns it?

36

How do you concatenate two strings "Hello" and "World" with a space in between?

37

Which symbol is used to call a function from a specific package without loading the whole package, e.g. dplyr's filter?

38

What does the function "head(df)" do?

39

Which assignment creates a global variable from inside a function in R?

40

Which RStudio/R function clears all objects from the current environment?

1

What is the difference between "[" and "[[" when subsetting a list in R?

2

What does the apply family function "sapply()" do?

3

In the magrittr/dplyr pipe "%>%", what does "df %>% filter(x > 1) %>% select(y)" mean?

4

What does "lapply(x, f)" return?

5

What is the purpose of the "dplyr::mutate()" function?

6

What does the "%in%" operator do?

7

How are environments different from lists in R?

8

What does "factor(x, levels = c("low", "medium", "high"), ordered = TRUE)" create?

9

What is "vectorization" in R and why is it preferred over explicit loops?

10

What does "tapply(data, group, function)" do?

11

What is the difference between "==" and "identical()" when comparing two R objects?

12

What does the "...": (ellipsis/dots) argument allow in a function definition like "function(x, ...)"?

13

What does "na.rm = TRUE" do when passed to functions like mean() or sum()?

14

What is the purpose of "set.seed(n)" in R?

15

What does "do.call(func, args_list)" do?

16

What is the difference between a "data.frame" and a "tibble" (from the tibble/dplyr package)?

17

What does "Reduce(function(a, b) a + b, c(1,2,3,4))" compute?

18

What is "lazy evaluation" of function arguments in R?

19

What does the function "merge(df1, df2, by = "id")" do?

20

What is the difference between "&" and "&&" in R?

21

What does "table(x)" return for a categorical vector x?

22

What does "regmatches(x, regexpr(pattern, x))" accomplish?

23

What is the purpose of S3 classes in R, e.g. defining a "print.myclass" method?

24

What does "stringr::str_detect(x, pattern)" return?

25

What is the purpose of "group_by()" combined with "summarise()" in dplyr?

26

What does "match.arg()" do inside a function definition?

27

What is the effect of "drop = FALSE" when subsetting a data frame, e.g. "df[, "col", drop = FALSE]"?

28

What does the "switch()" function do in R?

29

What is the purpose of the "apply(m, 1, sum)" call on a matrix m?

30

What does "Sys.time()" return?

31

What is the difference between "deep copy" semantics and reference semantics as they apply to standard R vectors and lists?

32

What does "Vectorize()" do to a non-vectorized function?

33

What does "complete.cases(df)" return?

34

What is the purpose of "on.exit()" inside a function?

35

What does "is.function(x)" check?

36

What does "names(df) <- c("a", "b", "c")" do for a data frame df with three columns?

37

What does the operator "%>%" require to be available in base R (prior to R 4.1)?

38

What does "as.Date("2024-01-15")" return?

39

What is the purpose of "pivot_longer()" and "pivot_wider()" from the tidyr package?

40

What does "ggplot(data, aes(x = a, y = b)) + geom_point()" produce?

1

What is the key difference between R's S4 class system and the S3 system?

2

What does "environment(f) <- new_env" change about a function f?

3

What is "non-standard evaluation" (NSE) and how does it relate to functions like "subset()" or dplyr verbs?

4

What does "memoise" (memoization) do, and how would it typically be implemented for an R function?

5

What is the purpose of "Rcpp" in the R ecosystem?

6

What does "force()" do when used inside a closure-generating function, e.g. in a loop creating multiple functions?

7

What is the difference between "quote()" and "eval()" in metaprogramming with R?

8

What does R's "promise" object represent in the context of lazy evaluation?

9

What is the difference between "tryCatch()" and "try()" for error handling?

10

What does the "data.table" package's syntax "DT[, newcol := value]" do compared to base R or dplyr equivalents?

11

What is the purpose of "match.call()" inside a function?

12

How does R's garbage collector generally decide when to free memory used by an object?

13

What is a key consideration when using "parallel::mclapply()" versus "lapply()"?

14

What does "sys.call()" versus "sys.function()" return when called inside a function?

15

In R6 or Reference Classes (R5), what makes objects behave differently from standard S3/S4 objects with respect to method calls modifying state?

16

What is the difference between "missing(x)" and "is.null(x)" when checking function arguments?

17

How does R handle "active bindings" in an environment or R6 class?

18

What does the "bquote()" function do, and how does it differ from "quote()"?

19

What is the significance of the "ALTREP" (Alternative Representation) framework introduced in R 3.5?

20

What is the practical implication of R functions being "first-class objects" with respect to passing functions as arguments, e.g. "Map(function(x, y) x + y, list1, list2)"?