What is the stringsAsFactors history in R and why did it matter?

Quick Overview

Asks what the stringsAsFactors setting in R used to do, why its default changed, and which problems it caused in everyday analysis code. Tests practical knowledge of R data frames, factor types and writing scripts that behave the same across R versions.

What is the stringsAsFactors history in R and why did it matter?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the `stringsAsFactors` history and why did it matter? The argument appears in `data.frame()`, `read.csv()` and related functions in base R. ```hint Follow one column Picture a CSV column of numbers with one stray text entry. Ask what type that column became after `read.csv()` in older R, and what `as.numeric()` does to that type. ``` ### What a Strong Answer Covers - What the old default was, which functions it affected, and what changed in R 4.0.0 - Why the default existed in the first place - Concrete bugs that silent factor conversion caused - How to write code whose behavior does not depend on the R version - When a factor is still the right type to use ### Follow-up Questions - Why does `as.numeric()` on a factor return codes, and how do you get the original numbers back? - When would you still convert a column to a factor on purpose? - How can factor levels break scoring a fitted model on new data? - Code written for R 3.x calls `levels(df$city)` on a column read with `read.csv()`. What happens under R 4.x?

Overview: Asks what the stringsAsFactors setting in R used to do, why its default changed, and which problems it caused in everyday analysis code. Tests practical knowledge of R data frames, factor types and writing scripts that behave the same across R versions.

General logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the stringsAsFactors history and why did it matter?

The argument appears in data.frame(), read.csv() and related functions in base R.

What a Strong Answer Covers Guidance

  • What the old default was, which functions it affected, and what changed in R 4.0.0
  • Why the default existed in the first place
  • Concrete bugs that silent factor conversion caused
  • How to write code whose behavior does not depend on the R version
  • When a factor is still the right type to use

Follow-up Questions Guidance

  • Why does as.numeric() on a factor return codes, and how do you get the original numbers back?
  • When would you still convert a column to a factor on purpose?
  • How can factor levels break scoring a fitted model on new data?
  • Code written for R 3.x calls levels(df$city) on a column read with read.csv() . What happens under R 4.x?