0
0
R Programmingprogramming~20 mins

select() for column selection in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
select() Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of select() with tidyselect helpers
What is the output of the following R code using dplyr::select() with tidyselect helpers?
R Programming
library(dplyr)
df <- tibble(a = 1:3, b = 4:6, c = 7:9, d = 10:12)
result <- df %>% select(starts_with("b"), ends_with("d"))
print(result)
AA tibble with columns a, b, c, d
BA tibble with columns a and c
CA tibble with columns b and d
DAn error because ends_with() is used incorrectly
Attempts:
2 left
💡 Hint
Think about which columns start with 'b' and which end with 'd'.
Predict Output
intermediate
2:00remaining
Result of select() with numeric range
What columns are selected by this code snippet?
R Programming
library(dplyr)
df <- tibble(x1 = 1:2, x2 = 3:4, y1 = 5:6, y2 = 7:8)
selected <- df %>% select(x1:y1)
print(selected)
AColumns x1, x2, y1, y2
BColumns x1, x2, y1
CColumns x1 and y1 only
DError because x1:y1 is invalid
Attempts:
2 left
💡 Hint
The colon operator selects columns between two names in order.
🔧 Debug
advanced
2:00remaining
Why does this select() call fail?
This code throws an error. What is the cause?
R Programming
library(dplyr)
df <- tibble(a = 1:3, b = 4:6)
selected <- df %>% select(a, c)
print(selected)
AColumn 'c' does not exist in the data frame
Bselect() cannot take multiple arguments
CThe pipe operator %>% is used incorrectly
DThe tibble function is missing parentheses
Attempts:
2 left
💡 Hint
Check if all columns you select exist in the data frame.
Predict Output
advanced
2:00remaining
Output of select() with helper functions and renaming
What is the output of this code?
R Programming
library(dplyr)
df <- tibble(name = c("Ann", "Bob"), age = c(25, 30), score = c(88, 92))
result <- df %>% select(person = name, age)
print(result)
AA tibble with columns 'age' and 'score' only
BA tibble with columns 'name' and 'age' unchanged
CAn error because select() cannot rename columns
DA tibble with columns 'person' and 'age', where 'person' has the names
Attempts:
2 left
💡 Hint
select() can rename columns by using new_name = old_name syntax.
🧠 Conceptual
expert
3:00remaining
Understanding select() with complex tidyselect expressions
Which option correctly describes the columns selected by this code?
R Programming
library(dplyr)
df <- tibble(a1 = 1, a2 = 2, b1 = 3, b2 = 4, c1 = 5)
selected <- df %>% select(matches("^a[12]$"), -a2)
print(selected)
AOnly column 'a1' is selected because 'a2' is excluded
BAn error occurs because negative selection cannot be combined with matches()
CColumns 'a1', 'a2', and 'b1' are selected
DColumns 'a1' and 'a2' are selected because matches() includes both
Attempts:
2 left
💡 Hint
Negative selection removes columns after positive selection.