21
How do you extract the first row of a data frame named my_data in R?
A)
my_data[1, ]
B)
my_data[first_row()]
C)
my_data[,"row" == 1]
D)
extract_row(my_data, 1)
Answer & Solution
Answer: Option
A
22
In R, what is the purpose of the table() function?
A)
Create a contingency table from factors
B)
Display a table of values
C)
Generate a summary of data using tables
D)
Count the number of rows and columns in a data frame
Answer & Solution
Answer: Option
A
23
How do you remove a column named Income from a data frame named my_data in R?
A)
my_data <- my_data[, -which(names(my_data) == "Income")]
B)
my_data$Income <- NULL
C)
drop_column(my_data, "Income")
D)
remove_col(my_data, "Income")
Answer & Solution
Answer: Option
B
24
In R, what does the unlist() function do?
A)
Converts a list to a vector
B)
Reverses the order of elements
C)
Creates an unsorted list
D)
Extracts unique elements from a vector
Answer & Solution
Answer: Option
A
25
How is a character string converted to a numeric vector in R using the as.numeric() function?
A)
as.numeric("123")
B)
numeric("123")
C)
convert_numeric("123")
D)
to_numeric("123")
Answer & Solution
Answer: Option
A
26
In R, what is the purpose of the subset() function?
A)
Create a subset of a data frame based on conditions
B)
Generate a summary of a data frame
C)
Filter data based on row and column indices
D)
Extract unique values from a vector using subsetting
Answer & Solution
Answer: Option
A
27
How do you add a new row to a data frame named my_data with values "Alice" and 28 for columns Name and Age?
A)
my_data <- rbind(my_data, c("Alice", 28))
B)
my_data <- add_row(my_data, Name = "Alice", Age = 28)
C)
my_data$Name <- "Alice"; my_data$Age <- 28
D)
append_row(my_data, c("Alice", 28))
Answer & Solution
Answer: Option
B
28
What function is used to concatenate two vectors in R?
A)
concat()
B)
paste()
C)
c()
D)
combine()
Answer & Solution
Answer: Option
C
29
In R, what does the slice() function do?
A)
Extracts specific rows from a data frame
B)
Dices a vector into smaller slices
C)
Counts the number of slices in a vector
D)
Slices a data frame into smaller data frames
Answer & Solution
Answer: Option
A
30
How do you create a named numeric vector with values 1, 2, and 3 named "one", "two", and "three" in R?
A)
named_vector <- c(one = 1, two = 2, three = 3)
B)
create_named_vec(1, 2, 3, names = c("one", "two", "three"))
C)
numeric_vector(c(1, 2, 3), names = c("one", "two", "three"))
D)
vec_named(c(1, 2, 3), c("one", "two", "three"))
Answer & Solution
Answer: Option
D