What is the output of this R code using pipe chaining?
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)
Remember filter keeps rows where x > 2, then z is y / x.
The filter keeps rows where x is 3, 4, 5. Then z is y divided by x: 6/3=2, 8/4=2, 10/5=2.
Which option correctly describes what this pipe chain does?
library(magrittr) result <- 1:5 %>% sum() %>% sqrt()
Remember pipe passes the result of one function as input to the next.
The pipe sends 1:5 to sum(), which returns 15, then sqrt(15) is calculated.
What error does this R code produce?
library(dplyr) data <- tibble(a = 1:3, b = 4:6) result <- data %>% select(a) %>% filter(b > 4)
Check which columns remain after select(a).
After selecting only column 'a', column 'b' is removed, so filter(b > 4) fails with 'object b not found'.
Which option shows the correct pipe chaining syntax in R?
Check if the pipe operators are used consistently.
Option A uses the magrittr pipe operator consistently. Mixing %>% and |> in one chain is invalid.
What is the value of final after running this code?
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)
Calculate squares, filter those divisible by 8, then sum.
Squares: 4, 16, 36, 64. Divisible by 8: 16, 64. Sum: 80.