31
In dplyr, what is the purpose of the distinct() function when used with multiple columns?
A)
Filters unique rows based on all specified columns
B)
Selects distinct values from the first column
C)
Selects distinct values from any column
D)
Filters unique rows based on the first column
Answer & Solution
Answer: Option
A
32
How do you create a new column total_price in dplyr that is the sum of two existing columns price1 and price2?
A)
mutate(total_price = sum(price1, price2))
B)
create_column(total_price = price1 + price2)
C)
calculate_total(total_price = price1 + price2)
D)
mutate(total_price = price1 + price2)
Answer & Solution
Answer: Option
D
33
What is the purpose of the filter() function in dplyr?
A)
Removes rows based on specified conditions
B)
Filters specific columns from a data frame
C)
Counts the number of unique values in a column
D)
Arranges rows in ascending order based on a column
Answer & Solution
Answer: Option
A
34
How do you select columns from a dplyr data frame where the column names start with the letter 'a'?
A)
select_cols(starts_with("a"))
B)
choose_columns(matches("a"))
C)
select(starts_with("a"))
D)
pick_cols(matches("a"))
Answer & Solution
Answer: Option
C
35
In dplyr, how do you calculate the sum and mean of a numeric variable named quantity for each group?
A)
summarize(total = sum(quantity), average = mean(quantity))
B)
calculate(sum = sum(quantity), mean = mean(quantity))
C)
summarize(sum_quantity = sum(quantity), mean_quantity = mean(quantity))
D)
total_mean(quantity)
Answer & Solution
Answer: Option
A
36
What is the role of the left_join() function in dplyr?
A)
Performs a left outer join between two data frames
B)
Merges data frames based on common columns
C)
Filters rows present in the left data frame
D)
Arranges the rows based on a common column
Answer & Solution
Answer: Option
A
37
In dplyr, how do you filter rows where a specific variable is within a range using filter()?
A)
filter(variable >= lower_bound & variable <= upper_bound)
B)
filter(between(variable, lower_bound, upper_bound))
C)
filter(variable > lower_bound & variable < upper_bound)
D)
filter(in_range(variable, lower_bound, upper_bound))
Answer & Solution
Answer: Option
B
38
How do you count the number of distinct values in a column named category in dplyr?
A)
count_distinct(category)
B)
distinct_count(category)
C)
calculate_distinct(category)
D)
n_distinct(category)
Answer & Solution
Answer: Option
D
39
In dplyr, how do you filter rows based on multiple conditions using the AND logic?
A)
filter(condition1 & condition2)
B)
filter_all_of(condition1, condition2)
C)
filter_condition(condition1 & condition2)
D)
filter(conditions = condition1, condition2)
Answer & Solution
Answer: Option
A
40
What does the desc() function do in dplyr?
A)
Sorts a column in descending order
B)
Describes the summary statistics of a column
C)
Discretizes a numeric column
D)
Disassembles a string column
Answer & Solution
Answer: Option
A