How does the switch() statement work in R and when would you use it?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Overview: Asks how the R switch() function picks a branch for string and numeric selectors and when it is a better choice than an if/else chain. Tests knowledge of defaults, fall-through, return values when nothing matches, and the limits of a non-vectorised function.