Unit 12: R Tool - Practice Quiz

ECAP792 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is R primarily used for?

Introduction to R Easy
A. Hardware design and testing
B. Statistical computing and graphics
C. Web hosting and routing
D. Video editing and animation

2 Which symbol is commonly used to assign a value to a variable in R?

Introduction to R Easy
A. !=
B. ==
C. <-
D. >=

3 What is RStudio?

RStudio Easy
A. An integrated development environment for R
B. A database management system for R
C. A spreadsheet file format for R
D. A programming language replacing R

4 Which RStudio pane normally displays commands and their immediate results?

RStudio Easy
A. Environment
B. Console
C. Files
D. Source

5 Which R data structure stores data in rows and columns while allowing columns to have different data types?

Important R data structures Easy
A. Dataframe
B. Vector
C. Matrix
D. Factor

6 Which R data structure is one-dimensional and usually contains elements of the same basic type?

Important R data structures Easy
A. Vector
B. List
C. Matrix
D. Dataframe

7 Which R function combines values to create a vector?

Vectors Easy
A. print()
B. dim()
C. sum()
D. c()

8 What is the result of length(c(5, 10, 15, 20))?

Vectors Easy
A. 4
B. 3
C. 20
D. 50

9 Which expression selects the second element of a vector named scores?

Vectors Easy
A. scores{2}
B. scores<2>
C. scores(2)
D. scores[2]

10 Which value is a valid character string in R?

Character strings Easy
A. Data Science
B. {Data Science}
C. "Data Science"
D. <Data Science>

11 Which function joins character strings together in R?

Character strings Easy
A. paste()
B. matrix()
C. length()
D. factor()

12 What is a matrix in R?

Matrices Easy
A. A function containing several arguments
B. A one-dimensional collection of mixed types
C. A table with unequal column lengths
D. A two-dimensional collection of one basic type

13 Which function is used to create a matrix in R?

Matrices Easy
A. data.frame()
B. list()
C. vector()
D. matrix()

14 Which expression selects the element in row 2 and column 3 of matrix m?

Matrices Easy
A. m(2, 3)
B. m[[2, 3]]
C. m[3, 2]
D. m[2, 3]

15 What is a key feature of an R list?

Lists Easy
A. It requires every element to be text
B. It always has exactly two dimensions
C. It can store elements of different types
D. It stores only numeric scalar values

16 Which function creates a list in R?

Lists Easy
A. table()
B. array()
C. levels()
D. list()

17 Which function creates a dataframe in R?

Dataframe Easy
A. as.vector()
B. data.frame()
C. character()
D. is.matrix()

18 How can the column named age be accessed from a dataframe named students?

Dataframe Easy
A. students$age
B. students@age
C. students#age
D. students%age

19 Which symbol begins a comment in R?

R programming structure Easy
A. **
B. <!--
C. //
D. #

20 Which keyword is used to define a function in R?

R programming structure Easy
A. define
B. function
C. method
D. procedure

21 What is returned by rep(seq(2, 6, by = 2), times = c(1, 2, 1))?

Introduction to R Medium
A. c(2, 4, 4, 6)
B. c(2, 2, 4, 6)
C. c(2, 4, 6, 6)
D. c(2, 2, 4, 4, 6, 6)

22 Given x <- c(4, 7, 9, 12), what does x[-c(1, 3)] return?

Introduction to R Medium
A. c(4, 9)
B. c(7, 12)
C. c(7, 9, 12)
D. c(4, 7, 9)

23 An RStudio project has its working directory set to the project root. What does read.csv("data/sales.csv") do?

RStudio Medium
A. Reads the file relative to the R installation
B. Reads the file relative to the project root
C. Searches installed packages for the file
D. Downloads the file into the project root

24 While editing an R script in RStudio, which action runs only the selected code in the active R session?

RStudio Medium
A. Use Knit or press Ctrl+Shift+K
B. Use Build or press Ctrl+Shift+B
C. Use Run or press Ctrl+Enter
D. Use Source without changing settings

25 Consider f <- factor(c("high", "low", "high"), levels = c("low", "high")). What does as.integer(f) return?

Important R data structures Medium
A. c(1, 1, 2)
B. c(1, 2, 1)
C. c(2, 1, 2)
D. c(2, 2, 1)

26 For f <- factor(c("A", "B", "A")), which pair correctly describes typeof(f) and class(f)?

Important R data structures Medium
A. typeof(f) is list; class(f) is character
B. typeof(f) is factor; class(f) is integer
C. typeof(f) is character; class(f) is factor
D. typeof(f) is integer; class(f) is factor

27 What is the result of c(1, 2) + c(10, 20, 30, 40)?

Vectors Medium
A. c(11, 22, 31, 42)
B. c(11, 22, 30, 40)
C. c(10, 40, 30, 80)
D. c(11, 21, 32, 42)

28 Given x <- c(10, 20, 30, 40, 50), what does x[c(TRUE, FALSE)] return?

Vectors Medium
A. c(20, 40)
B. c(10, 30, 50)
C. c(10, 20)
D. c(30, 40, 50)

29 What is the storage type and value of c(TRUE, 2L, 3.5)?

Vectors Medium
A. Logical vector c(TRUE, TRUE, TRUE)
B. Double vector c(1, 2, 3.5)
C. Integer vector c(1L, 2L, 3L)
D. Character vector c("TRUE", "2", "3.5")

30 What does paste(c("R", "Data", "Tool"), collapse = "-") return?

Character strings Medium
A. "R-Data-Tool"
B. c("R", "Data", "Tool")
C. c("R-", "Data-", "Tool")
D. "R Data Tool"

31 What is returned by grepl("^[A-Z][0-9]+$", c("A12", "ab3", "B7"))?

Character strings Medium
A. c(TRUE, FALSE, TRUE)
B. c(TRUE, TRUE, FALSE)
C. c(FALSE, TRUE, TRUE)
D. c(FALSE, FALSE, TRUE)

32 Given m <- matrix(1:8, nrow = 2), what does m[, 3] return?

Matrices Medium
A. c(3, 4)
B. c(5, 6)
C. c(3, 7)
D. c(2, 6)

33 Consider m <- matrix(1:6, nrow = 2, byrow = TRUE). What does apply(m, 2, sum) return?

Matrices Medium
A. c(6, 15)
B. c(5, 7, 9)
C. c(4, 6, 8)
D. c(3, 7, 11)

34 Given z <- list(a = 10, b = c(2, 4)), which expression returns the numeric value 4?

Lists Medium
A. z[["b"]][2]
B. z["b"][2]
C. z$b[1]
D. z[[2]][1]

35 What is the structure of lapply(c(1, 2, 3), function(v) v + 1)?

Lists Medium
A. A matrix containing 2, 3, and 4
B. A data frame containing 2, 3, and 4
C. A list containing 2, 3, and 4
D. A factor containing 2, 3, and 4

36 Given df <- data.frame(name = c("Ana", "Bo", "Cy"), group = c("A", "B", "A"), score = c(80, 90, 65)), what does df[df$group == "A" & df$score >= 70, "name"] return?

Dataframe Medium
A. "Bo"
B. c("Ana", "Cy")
C. "Ana"
D. "Cy"

37 Consider df <- data.frame(score = c(8, NA, 6)). After df$score[is.na(df$score)] <- mean(df$score, na.rm = TRUE), what is df$score?

Dataframe Medium
A. c(8, 6, 6)
B. c(8, NA, 6)
C. c(8, 7, 6)
D. c(8, 8, 6)

38 What are the values of result and global x after running x <- 10; f <- function(y) { x <- 2; x + y }; result <- f(3)?

R programming structure Medium
A. result is 13 and x is 2
B. result is 5 and x is 2
C. result is 13 and x is 10
D. result is 5 and x is 10

39 Given grade <- function(x) ifelse(x >= 50, "pass", "fail"), what does grade(c(40, 50, 70)) return?

R programming structure Medium
A. c("pass", "pass", "pass")
B. c("fail", "fail", "pass")
C. c("fail", "pass", "pass")
D. c("pass", "fail", "fail")

40 What is the final value of total after total <- 0; for (i in 1:5) { if (i %% 2 == 0) next; total <- total + i }?

R programming structure Medium
A. 6
B. 12
C. 9
D. 15

41 What is the value of c(identical(1, 1L), typeof(1), typeof(1L)) in R?

Introduction to R Hard
A. c(FALSE, "numeric", "integer")
B. c(FALSE, "double", "integer")
C. c(TRUE, "double", "integer")
D. c(TRUE, "numeric", "numeric")

42 Which statement correctly describes evaluating stats::filter(x, rep(1, 3)) when the stats package is not attached?

Introduction to R Hard
A. It fails because library(stats) must run first.
B. It attaches stats temporarily for this expression.
C. It copies every exported object from stats into the global environment before resolving the requested function.
D. It accesses the exported function without attaching stats.

43 Which statement about an RStudio Project is accurate?

RStudio Hard
A. It normally uses the project root as the working directory.
B. It automatically creates an isolated package library.
C. It rewrites absolute paths in every sourced script so that all file references become portable across operating systems.
D. It permanently prevents access to files outside the project.

44 Given f <- factor(c("b", "a", "b"), levels = c("b", "a")), what does c(sum(as.integer(f)), paste(as.character(f), collapse = "")) return?

Important R data structures Hard
A. c("3", "bab")
B. c("5", "aba")
C. c("4", "bab")
D. c("4", "121")

45 What value is returned by the final expression?

e1 <- new.env()

e1$x <- 1

e2 <- e1

e2$x <- 8

e1$x

Important R data structures Hard
A. NULL
B. 8
C. numeric(0)
D. 1

46 For x <- c(NA_real_, NaN, Inf, -Inf, 0), what is c(sum(is.na(x)), sum(is.nan(x)), sum(is.finite(x)))?

Vectors Hard
A. c(1, 1, 3)
B. c(1, 1, 1)
C. c(2, 2, 1)
D. c(2, 1, 1)

47 Given x <- c(a = 10, b = 20, a = 30), what does x[c("a", "a")] return?

Vectors Hard
A. c(a = 10, a = 10)
B. c(a = 10, a = 30)
C. c(a = 10, b = 20)
D. c(a = 30, a = 30)

48 After x <- 1:3; x[5] <- 9, which description of x is correct?

Vectors Hard
A. The assignment fails because position 4 has not previously been allocated.
B. It is the double vector c(1, 2, 3, 0, 9).
C. It is the double vector c(1, 2, 3, NA, 9).
D. It is the integer vector c(1L, 2L, 3L, NA, 9L).

49 What does sub(".", "-", "a.b.c", fixed = TRUE) return?

Character strings Hard
A. "a-b.c"
B. "a.b-c"
C. "-a.b.c"
D. "a-b-c"

50 What is returned by strsplit("a,b,", ",", fixed = TRUE)[[1]]?

Character strings Hard
A. c("a", "b")
B. A three-element vector in which the final component is retained as NA_character_ to represent the trailing separator.
C. c("a", "b", "")
D. c("a,b", "")

51 Given m <- matrix(1:6, nrow = 2), what is m[cbind(c(2, 1, 2), c(1, 3, 2))]?

Matrices Hard
A. c(1, 6, 3)
B. c(4, 5, 2)
C. c(2, 3, 6)
D. c(2, 5, 4)

52 For m <- matrix(1:6, nrow = 2), which pair describes m[1, , drop = FALSE]?

Matrices Hard
A. A matrix with dimensions c(1, 3)
B. A matrix with dimensions c(3, 1)
C. A vector with length 3
D. An array with dimensions c(1, 3, 1)

53 Given z <- list(a = list(b = 1:3), b = 4), what does z[[c("a", "b")]] return?

Lists Hard
A. list(a = list(b = 1:3))
B. 1:3
C. list(b = 1:3)
D. 4

54 With default R options and x <- list(alpha = 7, beta = 9), which expression evaluates to TRUE?

Lists Hard
A. identical(x[["al"]], 7) && is.null(x$al)
B. identical(x[["al"]], 7) && identical(x$al, 7)
C. is.null(x[["al"]]) && is.null(x$al)
D. is.null(x[["al"]]) && identical(x$al, 7)

55 Given d <- data.frame(x = 1:3, y = 4:6), what is the result of c(is.data.frame(d["x"]), is.data.frame(d[, "x"]), is.data.frame(d[, "x", drop = FALSE]))?

Dataframe Hard
A. c(TRUE, FALSE, TRUE)
B. c(FALSE, FALSE, TRUE)
C. c(TRUE, FALSE, FALSE)
D. c(TRUE, TRUE, TRUE)

56 Under the default check.names = TRUE, what is names(data.frame(x = 1:2, x = 3:4))?

Dataframe Hard
A. c("x", "x_1")
B. c("x.1", "x.2")
C. c("x", "x.1")
D. c("x", "x")

57 What does the following code return?

x <- 10

f <- function(y = x) {

x <- 20

y

}

f()

R programming structure Hard
A. NULL
B. An error about a recursive default argument
C. 20
D. 10

58 What is returned by the final expression?

make_counter <- function() {

x <- 0

function() { x <<- x + 1; x }

}

a <- make_counter()

b <- make_counter()

c(a(), a(), b())

R programming structure Hard
A. c(2, 2, 1)
B. c(1, 1, 1)
C. c(1, 2, 3)
D. c(1, 2, 1)

59 What happens when this code is evaluated?

f <- function(x) 1

f(stop("boom"))

R programming structure Hard
A. It returns a promise containing the error.
B. It returns 1 without an error.
C. It signals the error boom immediately.
D. It warns about an unused argument and returns 1.

60 What is returned by this code?

make_funs <- function() {

fs <- vector("list", 3)

for (i in 1:3) fs[[i]] <- function() i

fs

}

sapply(make_funs(), function(f) f())

R programming structure Hard
A. c(1, 2, 3)
B. c(NA, NA, NA)
C. c(3, 3, 3)
D. c(1, 1, 1)