1
Which data structure in R is used to store an ordered collection of elements?
A)
List
B)
Matrix
C)
Data Frame
D)
Vector
Answer & Solution
Answer: Option
D
2
What does the matrix() function create in R?
A)
A list of elements
B)
A one-dimensional array
C)
A two-dimensional array
D)
A data frame
Answer & Solution
Answer: Option
C
3
In R, how do you create a list named my_list with three elements: 1, "hello", and TRUE?
A)
my_list <- c(1, "hello", TRUE)
B)
my_list = list(1, "hello", TRUE)
C)
my_list(1, "hello", TRUE)
D)
list(my_list = c(1, "hello", TRUE))
Answer & Solution
Answer: Option
B
4
What is the primary data structure used for storing tabular data in R?
A)
List
B)
Matrix
C)
Data Frame
D)
Array
Answer & Solution
Answer: Option
C
5
How is a vector different from a list in R?
A)
Vectors can only store numeric values
B)
Lists can store elements of different types
C)
Lists can only store characters
D)
Vectors can store elements of different types
Answer & Solution
Answer: Option
D
6
In R, how is a matrix initialized with values 1 to 9 arranged in three rows?
A)
matrix(1:9, nrow = 3, ncol = 3)
B)
matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3)
C)
matrix(1:9, rows = 3, cols = 3)
D)
mat(1:9, 3, 3)
Answer & Solution
Answer: Option
A
7
How do you create a factor in R named color with levels "red", "green", and "blue"?
A)
factor(color, levels = c("red", "green", "blue"))
B)
factor(color, levels = "red", "green", "blue")
C)
factor(color = c("red", "green", "blue"))
D)
factor(color = c("red", "green", "blue"), levels = c("red", "green", "blue"))
Answer & Solution
Answer: Option
D
8
What is the purpose of the data.frame() function in R?
A)
Create a vector
B)
Create a data frame
C)
Create a matrix
D)
Create a list
Answer & Solution
Answer: Option
B
9
In R, how do you create a named list with elements "apple", "orange", and "banana"?
A)
list("apple", "orange", "banana")
B)
named_list(c("apple", "orange", "banana"))
C)
list(c("apple", "orange", "banana"))
D)
list(elements = c("apple", "orange", "banana"))
Answer & Solution
Answer: Option
D
10
What is the correct way to access the second element of a vector named my_vector in R?
A)
my_vector(2)
B)
my_vector[2]
C)
my_vector.2
D)
my_vector[[2]]
Answer & Solution
Answer: Option
B