Challenge - 5 Problems
dplyr Data Wrangling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this dplyr pipeline?
Consider the following R code using dplyr. What will be the output printed?
R Programming
library(dplyr) data <- tibble(x = 1:5, y = c(5, 4, 3, 2, 1)) result <- data %>% filter(x > 2) %>% mutate(z = x + y) %>% select(z) print(result)
Attempts:
2 left
💡 Hint
Filter keeps rows where x > 2, then z is x + y for those rows.
✗ Incorrect
Rows where x is 3,4,5 remain. Their y values are 3,2,1. So z = x + y = 6,6,6.
🧠 Conceptual
intermediate1:30remaining
Why does dplyr use the pipe operator %>%
Why does dplyr use the pipe operator %>% to chain commands?
Attempts:
2 left
💡 Hint
Think about how code readability improves with chaining.
✗ Incorrect
The pipe operator lets you write steps in order, making code easier to read and understand.
🔧 Debug
advanced2:00remaining
Identify the error in this dplyr code
What error does this code produce and why?
library(dplyr)
data <- tibble(a = 1:3, b = 4:6)
result <- data %>% filter(a > 1) %>% mutate(c = a + d)
print(result)
Attempts:
2 left
💡 Hint
Check if all columns used in mutate exist in the data.
✗ Incorrect
Column 'd' does not exist in the data, so mutate fails with object not found error.
📝 Syntax
advanced1:30remaining
Which option correctly groups and summarizes data with dplyr?
Given a data frame df with columns group and value, which code correctly calculates the mean value per group?
Attempts:
2 left
💡 Hint
Remember the order: group_by first, then summarize.
✗ Incorrect
Option A correctly groups by 'group' then summarizes mean of 'value'. Others misuse function order or arguments.
🚀 Application
expert2:30remaining
How does dplyr simplify complex data wrangling tasks?
Which statement best explains why dplyr simplifies data wrangling compared to base R?
Attempts:
2 left
💡 Hint
Think about how dplyr verbs describe actions clearly.
✗ Incorrect
dplyr uses clear verbs like filter, mutate, summarize and the pipe operator to write readable, concise code.