Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

tidyr-basics

tidyr basics (local install)

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches tidyr basics (local install): the syntax, patterns, and safety habits you need before advancing in R.

Teams still ship tidyr basics (local install) in R codebases—skipping it leaves gaps in debugging and code reviews.

You will apply tidyr basics (local install) in contexts like: Clinical trial tables, survey cleaning, and feature engineering before Python ML.

Write R in the editor and click Run on server—the dev runner executes with Rscript; use print() or cat() and base R in playground snippets (tidyverse locally; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

tidyr reshapes data between wide and long forms—pivot_longer and pivot_wider replace older gather/spread. Install locally; playground demonstrates base reshape() concepts.

Why reshape?

Charts and models often need one observation per row. SQL pivots in warehouses mirror this—see SQL GROUP BY and CASE patterns.

tidyr locally

library(tidyr)
# pivot_longer(cols = ..., names_to = "metric", values_to = "value")

Base mindset

wide <- data.frame(id = 1:2, a = c(10, 20), b = c(30, 40))
print(wide)

Understand wide vs long before reaching for tidyr helpers.

Important interview questions and answers

  1. Q: Wide vs long data?
    A: Wide: many metric columns; long: key-value pairs stacked—ggplot2 often prefers long.
  2. Q: tidyr vs SQL pivot?
    A: Both reshape tables; SQL pivots at query time; tidyr in R after import.

Self-check

  1. Why might you pivot longer before plotting?
  2. What package installs tidyr?

Tip: Long format often follows SQL unpivot patterns—see SQL CASE/UNION strategies too.

Interview prep

Why pivot long?

Many charts and models expect one row per observation-metric pair.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • pivot_longer when?
  • separate_rows?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump