0
0
R Programmingprogramming~20 mins

Pipe chaining operations in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pipe chaining with dplyr filter and mutate

What is the output of this R code using pipe chaining?

R Programming
library(dplyr)
data <- tibble(x = 1:5, y = c(2, 4, 6, 8, 10))
result <- data %>% filter(x > 2) %>% mutate(z = y / x) %>% pull(z)
print(result)
A[1] 2 2 2
B[1] 3 2 2
C[1] 2 2 3
D[1] 2 3 2
Attempts:
2 left
💡 Hint

Remember filter keeps rows where x > 2, then z is y / x.

🧠 Conceptual
intermediate
1:30remaining
Understanding pipe chaining with base R and magrittr

Which option correctly describes what this pipe chain does?

R Programming
library(magrittr)
result <- 1:5 %>% sum() %>% sqrt()
ACalculates the sum of numbers 1 to 5 and then squares the result
BCalculates the square root of the sum of numbers 1 to 5
CCalculates the sum of the square roots of numbers 1 to 5
DCalculates the square root of each number from 1 to 5 and sums them
Attempts:
2 left
💡 Hint

Remember pipe passes the result of one function as input to the next.

🔧 Debug
advanced
2:00remaining
Identify the error in this pipe chain

What error does this R code produce?

R Programming
library(dplyr)
data <- tibble(a = 1:3, b = 4:6)
result <- data %>% select(a) %>% filter(b > 4)
AError: unexpected symbol in filter
BNo error, returns filtered tibble
CError: object 'b' not found
DError: select() expects at least one column
Attempts:
2 left
💡 Hint

Check which columns remain after select(a).

📝 Syntax
advanced
1:30remaining
Which pipe chaining syntax is correct?

Which option shows the correct pipe chaining syntax in R?

Adata %>% filter(x > 1) %>% mutate(y = x * 2)
Bdata |> filter(x > 1) %>% mutate(y = x * 2)
Cdata %>% filter(x > 1) |> mutate(y = x * 2)
Ddata |> filter(x > 1) |> mutate(y = x * 2)
Attempts:
2 left
💡 Hint

Check if the pipe operators are used consistently.

🚀 Application
expert
3:00remaining
Result of complex pipe chaining with multiple functions

What is the value of final after running this code?

R Programming
library(dplyr)
library(magrittr)
data <- tibble(val = c(2, 4, 6, 8))
final <- data %>%
  mutate(sq = val^2) %>%
  filter(sq %% 8 == 0) %>%
  summarise(total = sum(sq)) %>%
  pull(total)
print(final)
A100
B64
C120
D80
Attempts:
2 left
💡 Hint

Calculate squares, filter those divisible by 8, then sum.