R MCQ
Test your R knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
What is R primarily used for?
2Which operator is most commonly used for assignment in R?
3How do you print the value of a variable x to the console?
4Which function returns the number of elements in a vector?
5How do you create a vector containing the numbers 1, 2, and 3?
6Which data structure in R can hold elements of different types (e.g., numbers, strings, logical values) together?
7What function is used to check the class/type of an object?
8How do you create a comment in R?
9Which function reads a CSV file into a data frame?
10What does NA represent in R?
11Which symbol is used to access a column in a data frame by name?
12How do you create a sequence of numbers from 1 to 10?
13What is the function to install a package in R?
14Which function loads an installed package into the current session?
15What is the result of TRUE + TRUE in R?
16Which function returns summary statistics (min, max, mean, quartiles) for a numeric vector?
17How do you create a function in R that adds two numbers?
18What does the "str()" function do when applied to an object?
19Which function checks if a value is missing (NA)?
20How do you create a matrix with 2 rows and 3 columns from the numbers 1 through 6?
21What is the result of "5 %% 2" in R?
22Which function is used to remove an object from the current R environment?
23How do you select the first element of a vector named v?
24Which function converts a character string to numeric?
25What does the "if-else" structure look like in R for checking if x is greater than 10?
26Which loop construct repeats a block of code for each element in a vector?
27What is the default value of an uninitialized logical comparison result when comparing NA to anything, e.g. "NA == 5"?
28Which function combines two data frames by stacking their rows?
29What is the correct way to get help/documentation for the function "mean" in R?
30Which built-in constant represents an infinite value in R?
31How do you create a factor variable from a character vector?
32What does the function "nrow(df)" return for a data frame df?
33Which operator is used for logical AND in R when working with single values in an if condition?
34Which function generates a sequence of random numbers from a normal distribution?
35What is the working directory in R and which function returns it?
36How do you concatenate two strings "Hello" and "World" with a space in between?
37Which symbol is used to call a function from a specific package without loading the whole package, e.g. dplyr's filter?
38What does the function "head(df)" do?
39Which assignment creates a global variable from inside a function in R?
40Which RStudio/R function clears all objects from the current environment?
What is the difference between "[" and "[[" when subsetting a list in R?
2What does the apply family function "sapply()" do?
3In the magrittr/dplyr pipe "%>%", what does "df %>% filter(x > 1) %>% select(y)" mean?
4What does "lapply(x, f)" return?
5What is the purpose of the "dplyr::mutate()" function?
6What does the "%in%" operator do?
7How are environments different from lists in R?
8What does "factor(x, levels = c("low", "medium", "high"), ordered = TRUE)" create?
9What is "vectorization" in R and why is it preferred over explicit loops?
10What does "tapply(data, group, function)" do?
11What is the difference between "==" and "identical()" when comparing two R objects?
12What does the "...": (ellipsis/dots) argument allow in a function definition like "function(x, ...)"?
13What does "na.rm = TRUE" do when passed to functions like mean() or sum()?
14What is the purpose of "set.seed(n)" in R?
15What does "do.call(func, args_list)" do?
16What is the difference between a "data.frame" and a "tibble" (from the tibble/dplyr package)?
17What does "Reduce(function(a, b) a + b, c(1,2,3,4))" compute?
18What is "lazy evaluation" of function arguments in R?
19What does the function "merge(df1, df2, by = "id")" do?
20What is the difference between "&" and "&&" in R?
21What does "table(x)" return for a categorical vector x?
22What does "regmatches(x, regexpr(pattern, x))" accomplish?
23What is the purpose of S3 classes in R, e.g. defining a "print.myclass" method?
24What does "stringr::str_detect(x, pattern)" return?
25What is the purpose of "group_by()" combined with "summarise()" in dplyr?
26What does "match.arg()" do inside a function definition?
27What is the effect of "drop = FALSE" when subsetting a data frame, e.g. "df[, "col", drop = FALSE]"?
28What does the "switch()" function do in R?
29What is the purpose of the "apply(m, 1, sum)" call on a matrix m?
30What does "Sys.time()" return?
31What is the difference between "deep copy" semantics and reference semantics as they apply to standard R vectors and lists?
32What does "Vectorize()" do to a non-vectorized function?
33What does "complete.cases(df)" return?
34What is the purpose of "on.exit()" inside a function?
35What does "is.function(x)" check?
36What does "names(df) <- c("a", "b", "c")" do for a data frame df with three columns?
37What does the operator "%>%" require to be available in base R (prior to R 4.1)?
38What does "as.Date("2024-01-15")" return?
39What is the purpose of "pivot_longer()" and "pivot_wider()" from the tidyr package?
40What does "ggplot(data, aes(x = a, y = b)) + geom_point()" produce?
What is the key difference between R's S4 class system and the S3 system?
2What does "environment(f) <- new_env" change about a function f?
3What is "non-standard evaluation" (NSE) and how does it relate to functions like "subset()" or dplyr verbs?
4What does "memoise" (memoization) do, and how would it typically be implemented for an R function?
5What is the purpose of "Rcpp" in the R ecosystem?
6What does "force()" do when used inside a closure-generating function, e.g. in a loop creating multiple functions?
7What is the difference between "quote()" and "eval()" in metaprogramming with R?
8What does R's "promise" object represent in the context of lazy evaluation?
9What is the difference between "tryCatch()" and "try()" for error handling?
10What does the "data.table" package's syntax "DT[, newcol := value]" do compared to base R or dplyr equivalents?
11What is the purpose of "match.call()" inside a function?
12How does R's garbage collector generally decide when to free memory used by an object?
13What is a key consideration when using "parallel::mclapply()" versus "lapply()"?
14What does "sys.call()" versus "sys.function()" return when called inside a function?
15In R6 or Reference Classes (R5), what makes objects behave differently from standard S3/S4 objects with respect to method calls modifying state?
16What is the difference between "missing(x)" and "is.null(x)" when checking function arguments?
17How does R handle "active bindings" in an environment or R6 class?
18What does the "bquote()" function do, and how does it differ from "quote()"?
19What is the significance of the "ALTREP" (Alternative Representation) framework introduced in R 3.5?
20What 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)"?