How do separate() and unite() work in tidyr for splitting and combining columns?

Quick Overview

Explain how the tidyr functions separate() and unite() split one column into several and combine several columns into one in R. It tests your knowledge of their main arguments, how separators are interpreted, and how mismatched pieces and missing values are handled.

How do separate() and unite() work in tidyr for splitting and combining columns?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

How do `separate()` and `unite()` work in tidyr for splitting and combining columns? ```hint Look at the edge cases Think about what each function does when a value splits into more or fewer pieces than the column names you gave, and when one of the columns being combined is missing. ``` ### What a Strong Answer Covers - What each function does and the arguments that control it: source and target columns, the separator, and whether the inputs are kept. - How the separator is interpreted, including numeric positions. - What happens when a value has too many or too few pieces, and how missing values are handled when combining. - Type conversion of the new columns, and the newer `separate_wider_*()` functions. ### Follow-up Questions - How would you split a column holding a variable number of comma-separated tags into one row per tag? - Why does `separate(df, x, into = c("a", "b"), sep = ".")` return empty strings, and how do you fix it? - If you split `"2024-01"` into year and month and then unite them again, when do you get back the original value? - How does `separate_wider_delim()` behave differently from `separate()` when a value has too many pieces?

Overview: Explain how the tidyr functions separate() and unite() split one column into several and combine several columns into one in R. It tests your knowledge of their main arguments, how separators are interpreted, and how mismatched pieces and missing values are handled.

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

How do separate() and unite() work in tidyr for splitting and combining columns?

What a Strong Answer Covers Guidance

  • What each function does and the arguments that control it: source and target columns, the separator, and whether the inputs are kept.
  • How the separator is interpreted, including numeric positions.
  • What happens when a value has too many or too few pieces, and how missing values are handled when combining.
  • Type conversion of the new columns, and the newer separate_wider_*() functions.

Follow-up Questions Guidance

  • How would you split a column holding a variable number of comma-separated tags into one row per tag?
  • Why does separate(df, x, into = c("a", "b"), sep = ".") return empty strings, and how do you fix it?
  • If you split "2024-01" into year and month and then unite them again, when do you get back the original value?
  • How does separate_wider_delim() behave differently from separate() when a value has too many pieces?