0
0
R Programmingprogramming~30 mins

Why tidy data enables analysis in R Programming - See It in Action

Choose your learning style9 modes available
Why tidy data enables analysis
📖 Scenario: Imagine you work in a small bakery. You keep track of daily sales for different types of bread. The data is messy and hard to understand. You want to tidy it so you can easily find out which bread sells best each day.
🎯 Goal: You will create a small messy data frame, then tidy it step-by-step using R. This will help you see why tidy data makes analysis easier and faster.
📋 What You'll Learn
Create a data frame called sales with messy sales data
Create a vector called days with day names
Use tidyr::pivot_longer() to tidy the data into a long format
Print the tidy data frame called tidy_sales
💡 Why This Matters
🌍 Real World
Tidy data helps businesses quickly analyze sales trends by day or product.
💼 Career
Data analysts and scientists use tidy data to prepare datasets for clear and efficient analysis.
Progress0 / 4 steps
1
Create messy sales data
Create a data frame called sales with columns bread, Monday, and Tuesday. Use these exact values: bread has "Sourdough", "Baguette", "Rye"; Monday has 10, 15, 7; Tuesday has 12, 18, 5.
R Programming
Need a hint?

Use data.frame() with named vectors for each column.

2
Create a vector of days
Create a character vector called days with the exact values "Monday" and "Tuesday".
R Programming
Need a hint?

Use c() to create a vector with the two day names.

3
Tidy the sales data
Use tidyr::pivot_longer() on sales to create a new data frame called tidy_sales. Pivot the columns Monday and Tuesday into two columns: day and sales. Use names_to = "day" and values_to = "sales".
R Programming
Need a hint?

Use pivot_longer() with cols = days to select the day columns.

4
Print the tidy data
Print the tidy_sales data frame to see the tidy data format.
R Programming
Need a hint?

Use print(tidy_sales) to show the tidy data frame.