0
0
R Programmingprogramming~10 mins

Pipe chaining operations in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to chain the operations using the pipe operator.

R Programming
library(dplyr)
data <- data.frame(x = 1:5, y = 6:10)
result <- data [1] filter(x > 2)
Drag options to blanks, or click blank then click option'
A%$%
B%>%
C%T>%
D%<>%
Attempts:
3 left
💡 Hint
Common Mistakes
Using other pipe operators like %$% or %T>% which have different purposes.
2fill in blank
medium

Complete the code to select column 'y' after filtering.

R Programming
library(dplyr)
data <- data.frame(x = 1:5, y = 6:10)
result <- data %>% filter(x > 2) [1] select(y)
Drag options to blanks, or click blank then click option'
A%>%
B%$%
C%T>%
D%<>%
Attempts:
3 left
💡 Hint
Common Mistakes
Using different pipe operators that do not chain functions properly.
3fill in blank
hard

Fix the error in the pipe chain to calculate the mean of column 'y'.

R Programming
library(dplyr)
data <- data.frame(x = 1:5, y = 6:10)
mean_y <- data %>% filter(x > 2) [1] summarise(mean_y = mean(y))
Drag options to blanks, or click blank then click option'
A%T>%
B%$%
C%>%
D%<>%
Attempts:
3 left
💡 Hint
Common Mistakes
Using %$% which exposes variables but does not chain properly here.
4fill in blank
hard

Fill both blanks to create a pipe chain that filters and then mutates a new column.

R Programming
library(dplyr)
data <- data.frame(x = 1:5, y = 6:10)
result <- data [1] filter(x >= 3) [2] mutate(z = y * 2)
Drag options to blanks, or click blank then click option'
A%>%
B%T>%
C%<>%
D%$%
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different pipe operators in the same chain.
5fill in blank
hard

Fill all three blanks to chain filter, mutate, and then select columns.

R Programming
library(dplyr)
data <- data.frame(x = 1:5, y = 6:10)
result <- data [1] filter(x < 5) [2] mutate(z = y + 1) [3] select(x, z)
Drag options to blanks, or click blank then click option'
A%$%
B%>%
C%<>%
D%T>%
Attempts:
3 left
💡 Hint
Common Mistakes
Using different pipe operators that break the chain.