Back to Practice
#0178

Parse a Date Column in R

EasyR15 min10 XP

Problem

Given a data frame with date_text in YYYY-MM-DD format, add a date column using as.Date.

Why This Matters

Date columns must be real dates before sorting, filtering windows, or plotting time series.

Examples

Example 1
Inputdate_text values 2026-01-01 and 2026-01-10
Outputdate column contains Date values

as.Date turns ISO strings into proper date objects.

Constraints

  • Return the exact requested output.
  • Handle ordinary edge cases.
  • Prefer simple, interview-readable code.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputdate_text values 2026-01-01 and 2026-01-10
Expecteddate column contains Date values

as.Date turns ISO strings into proper date objects.

Hidden Test Categories
empty or minimal inputduplicates or tieslarger input