Back to Practice
#0163
Create a Category With ifelse in R
EasyR15 min10 XP
Problem
Given a data frame with score, add a band column equal to high when score >= 80, otherwise regular.
Why This Matters
Simple feature creation in R often starts with vectorized ifelse instead of row-by-row loops.
Examples
Example 1
Inputscores 92 and 70
Outputbands high and regular
The condition is checked element-wise for the whole score column.
Constraints
- Return the exact requested value.
- Handle empty or small inputs when the prompt allows them.
- Keep the code readable and deterministic.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputscores 92 and 70
Expectedbands high and regular
The condition is checked element-wise for the whole score column.
Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input