Back to Practice
#0048
Filter Rows in a Data Frame
EasyR12 min10 XP
Problem
Given a data frame customers with columns name, active, and spend, return only active customers whose spend is at least 1000.
Why This Matters
Filtering rows is one of the first moves in any R analysis. If you cannot subset cleanly, every later summary can be wrong.
Function Signature
customers[condition, ]
Examples
Example 1
Inputactive = TRUE and spend >= 1000
OutputAsha and Dev
Ben has enough spend but is inactive. Cara is active but below the spend threshold.
Constraints
- Use base R data-frame indexing.
- Keep all columns in the returned data frame.
- Use & for element-wise AND between row conditions.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Two rows satisfy both conditions
InputAsha, Ben, Cara, Dev rows
ExpectedAsha and Dev
Both conditions must be true for the same row.
Hidden Test Categories
No rows matchAll rows matchSpend exactly equals the threshold