Challenge - 5 Problems
Filtering Rows Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of filtering rows with dplyr filter()
What is the output of this R code that filters rows where score is greater than 80?
R Programming
library(dplyr) data <- data.frame(name = c("Anna", "Ben", "Cara", "Dan"), score = c(75, 85, 90, 60)) filtered <- filter(data, score > 80) print(filtered)
Attempts:
2 left
💡 Hint
Look for rows where score is more than 80.
✗ Incorrect
The filter() function keeps only rows where the condition score > 80 is TRUE. So only Ben and Cara remain.
❓ Predict Output
intermediate2:00remaining
Filtering rows with base R subset()
What will this R code print after filtering rows where age is less than or equal to 30?
R Programming
data <- data.frame(name = c("Eva", "Frank", "Gina", "Hank"), age = c(25, 35, 30, 40)) result <- subset(data, age <= 30) print(result)
Attempts:
2 left
💡 Hint
subset() keeps rows where the condition is TRUE.
✗ Incorrect
Rows with age 25 and 30 satisfy age <= 30, so Eva and Gina are kept.
❓ Predict Output
advanced2:00remaining
Filtering rows with multiple conditions
What is the output of this R code filtering rows where score is above 70 and grade is 'A'?
R Programming
library(dplyr) data <- data.frame(name = c("Ivy", "Jack", "Kara", "Liam"), score = c(80, 90, 65, 85), grade = c("B", "A", "A", "A")) filtered <- filter(data, score > 70 & grade == "A") print(filtered)
Attempts:
2 left
💡 Hint
Both conditions score > 70 and grade == 'A' must be true.
✗ Incorrect
Only Jack and Liam have scores above 70 and grade 'A'. Ivy has grade 'B', Kara has score 65.
❓ Predict Output
advanced2:00remaining
Filtering rows with NA values
What will this R code print after filtering rows where value is not NA?
R Programming
data <- data.frame(id = 1:5, value = c(10, NA, 20, NA, 30)) filtered <- subset(data, !is.na(value)) print(filtered)
Attempts:
2 left
💡 Hint
Use !is.na() to keep rows without missing values.
✗ Incorrect
Rows with NA in value are removed, so only rows 1, 3, and 5 remain.
❓ Predict Output
expert3:00remaining
Filtering rows with complex condition and mutate
What is the output of this R code that filters rows where new_score is above 50 after mutation?
R Programming
library(dplyr) library(magrittr) data <- data.frame(name = c("Mia", "Ned", "Oli", "Pam"), score = c(40, 60, 55, 45)) result <- data %>% mutate(new_score = score * 1.2) %>% filter(new_score > 50) print(result)
Attempts:
2 left
💡 Hint
First multiply score by 1.2, then keep rows where new_score > 50.
✗ Incorrect
Mia's new_score is 48 (40*1.2), Pam's is 54 (45*1.2). Only Ned (72) and Oli (66) have new_score > 50.