11
How do you check the structure of a data frame named my_data in R?
A)
struct(my_data)
B)
str(my_data)
C)
structure(my_data)
D)
check_structure(my_data)
Answer & Solution
Answer: Option
B
12
In R, what is the purpose of the names() function?
A)
Retrieve the number of elements in an object
B)
Set or retrieve names of an object
C)
Assign names to the elements
D)
Remove names from an object
Answer & Solution
Answer: Option
C
13
What function is used to convert a factor to a character vector in R?
A)
as.factor()
B)
as.character()
C)
to.character()
D)
factor_to_char()
Answer & Solution
Answer: Option
B
14
How is a data frame column named Age selected in R?
A)
data$Age
B)
data[,"Age"]
C)
data[["Age"]]
D)
data.column("Age")
Answer & Solution
Answer: Option
B
15
In R, how do you add a new column named Height to a data frame named my_data?
A)
my_data$Height <- c(160, 170, 155)
B)
add_column(my_data, "Height", c(160, 170, 155))
C)
my_data[,"Height"] <- c(160, 170, 155)
D)
append_column(my_data, "Height", c(160, 170, 155))
Answer & Solution
Answer: Option
A
16
How do you create a character vector with the elements "apple", "orange", and "banana" in R?
A)
char_vec <- c("apple", "orange", "banana")
B)
vector("apple", "orange", "banana")
C)
create_char_vector("apple", "orange", "banana")
D)
char_vec(c("apple", "orange", "banana"))
Answer & Solution
Answer: Option
A
17
What does the str() function do in R?
A)
Display the structure of an object
B)
Convert object to a string
C)
Compute the mean of an object
D)
Check the type of an object using string comparison
Answer & Solution
Answer: Option
A
18
In R, how do you create a data frame named my_df with columns Name and Age?
A)
my_df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, 30))
B)
create_df(Name = c("Alice", "Bob"), Age = c(25, 30))
C)
df(Name = c("Alice", "Bob"), Age = c(25, 30))
D)
data_frame(Name = c("Alice", "Bob"), Age = c(25, 30))
Answer & Solution
Answer: Option
A
19
What is the result of length(unique(c(1, 2, 3, 1, 2))) in R?
A)
3
B)
5
C)
2
D)
4
Answer & Solution
Answer: Option
A
20
In R, how is a factor converted to a numeric vector using the as.numeric() function?
A)
as.numeric(factor_vector)
B)
factor_vector(as.numeric)
C)
numeric(factor_vector)
D)
to.numeric(factor_vector)
Answer & Solution
Answer: Option
C