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. Video editing and animation
B. Statistical computing and graphics
C. Hardware design and testing
D. Web hosting and routing

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. A database management system for R
B. A spreadsheet file format for R
C. An integrated development environment for R
D. A programming language replacing R

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

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

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. Vector
B. Dataframe
C. Factor
D. Matrix

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

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

7 Which R function combines values to create a vector?

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

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

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

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. matrix()
B. paste()
C. factor()
D. length()

12 What is a matrix in R?

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

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

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

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 always has exactly two dimensions
B. It stores only numeric scalar values
C. It can store elements of different types
D. It requires every element to be text

16 Which function creates a list in R?

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

17 Which function creates a dataframe in R?

Dataframe Easy
A. data.frame()
B. character()
C. as.vector()
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. method
B. function
C. procedure
D. define

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

Introduction to R Medium
A. c(2, 2, 4, 4, 6, 6)
B. c(2, 4, 4, 6)
C. c(2, 2, 4, 6)
D. c(2, 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, 7, 9)
B. c(7, 12)
C. c(7, 9, 12)
D. c(4, 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. Downloads the file into the project root
C. Reads the file relative to the project root
D. Searches installed packages for the file

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

RStudio Medium
A. Use Run or press Ctrl+Enter
B. Use Build or press Ctrl+Shift+B
C. Use Knit or press Ctrl+Shift+K
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(2, 1, 2)
B. c(2, 2, 1)
C. c(1, 1, 2)
D. c(1, 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 character; class(f) is factor
B. typeof(f) is factor; class(f) is integer
C. typeof(f) is list; class(f) is character
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, 21, 32, 42)
B. c(11, 22, 30, 40)
C. c(11, 22, 31, 42)
D. c(10, 40, 30, 80)

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

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

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

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

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

Character strings Medium
A. c("R", "Data", "Tool")
B. c("R-", "Data-", "Tool")
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, FALSE, TRUE)
D. c(FALSE, TRUE, TRUE)

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

Matrices Medium
A. c(3, 7)
B. c(3, 4)
C. c(2, 6)
D. c(5, 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(3, 7, 11)
C. c(5, 7, 9)
D. c(4, 6, 8)

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

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

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

Lists Medium
A. A factor containing 2, 3, and 4
B. A data frame containing 2, 3, and 4
C. A list containing 2, 3, and 4
D. A matrix 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. "Cy"
B. "Bo"
C. c("Ana", "Cy")
D. "Ana"

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, 7, 6)
B. c(8, NA, 6)
C. c(8, 8, 6)
D. c(8, 6, 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("pass", "fail", "fail")
C. c("fail", "fail", "pass")
D. c("fail", "pass", "pass")

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. 9
B. 6
C. 12
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, "double", "integer")
B. c(TRUE, "numeric", "numeric")
C. c(TRUE, "double", "integer")
D. c(FALSE, "numeric", "integer")

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 attaches stats temporarily for this expression.
B. It copies every exported object from stats into the global environment before resolving the requested function.
C. It accesses the exported function without attaching stats.
D. It fails because library(stats) must run first.

43 Which statement about an RStudio Project is accurate?

RStudio Hard
A. It rewrites absolute paths in every sourced script so that all file references become portable across operating systems.
B. It normally uses the project root as the working directory.
C. It automatically creates an isolated package library.
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("5", "aba")
B. c("4", "bab")
C. c("4", "121")
D. c("3", "bab")

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. 1
B. 8
C. NULL
D. numeric(0)

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(2, 2, 1)
C. c(1, 1, 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 = 30, a = 30)
B. c(a = 10, a = 30)
C. c(a = 10, a = 10)
D. c(a = 10, b = 20)

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

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

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. c("a", "b")
C. A three-element vector in which the final component is retained as NA_character_ to represent the trailing separator.
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(2, 3, 6)
B. c(2, 5, 4)
C. c(4, 5, 2)
D. c(1, 6, 3)

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

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

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

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

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

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

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(FALSE, FALSE, TRUE)
B. c(TRUE, FALSE, FALSE)
C. c(TRUE, FALSE, TRUE)
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.1", "x.2")
B. c("x", "x_1")
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. 10
B. An error about a recursive default argument
C. NULL
D. 20

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(1, 1, 1)
B. c(1, 2, 3)
C. c(1, 2, 1)
D. c(2, 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 warns about an unused argument and returns 1.
C. It signals the error boom immediately.
D. It returns 1 without an error.

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(NA, NA, NA)
B. c(3, 3, 3)
C. c(1, 1, 1)
D. c(1, 2, 3)