Challenge - 5 Problems
Pipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pipe with dplyr and base R
What is the output of this R code using the pipe operator %>% from dplyr?
R Programming
library(dplyr) result <- mtcars %>% filter(cyl == 6) %>% summarise(avg_mpg = mean(mpg)) %>% pull(avg_mpg) print(round(result, 2))
Attempts:
2 left
💡 Hint
Look at the cars with 6 cylinders and calculate their average mpg.
✗ Incorrect
The code filters mtcars for 6-cylinder cars, then calculates the mean mpg, which is approximately 19.74.
❓ Predict Output
intermediate2:00remaining
Output of base R pipe |> with nested functions
What is the output of this R code using the base pipe operator |>?
R Programming
result <- 1:5 |> sum() |> sqrt() print(round(result, 3))
Attempts:
2 left
💡 Hint
Sum 1 to 5, then take the square root.
✗ Incorrect
Sum of 1 to 5 is 15, square root of 15 is approximately 3.873.
🔧 Debug
advanced2:00remaining
Identify the error in pipe usage
What error does this R code produce when using the pipe operator %>%?
R Programming
library(dplyr) result <- mtcars %>% filter(cyl == 4) %>% summarise(avg_hp = mean(hp)) %>% select(avg_hp) %>% mean() print(result)
Attempts:
2 left
💡 Hint
Check what class the object is before calling mean().
✗ Incorrect
select(avg_hp) returns a data frame, mean() expects a numeric vector, so it produces "Error: no applicable method for 'mean' applied to an object of class 'data.frame'".
🧠 Conceptual
advanced2:00remaining
Understanding pipe operator behavior
Which statement best describes the difference between %>% and |> in R?
Attempts:
2 left
💡 Hint
Think about package origin and placeholder usage.
✗ Incorrect
%>% comes from magrittr and supports the dot placeholder for the left-hand side; |> is a base R pipe introduced in R 4.1 and does not support the dot placeholder.
❓ Predict Output
expert2:00remaining
Output of complex pipe with anonymous function
What is the output of this R code using the base pipe |> with an anonymous function?
R Programming
result <- 1:4 |> ((x) x * 2)() |> sum() print(result)
Attempts:
2 left
💡 Hint
Anonymous function doubles each element, then sum them.
✗ Incorrect
1:4 is doubled to 2,4,6,8; sum is 20.