Using mutate() to Add New Columns in R
📖 Scenario: You work in a small bakery and keep track of daily sales data in a table. You want to add new columns to calculate the total revenue and a label for high or low sales days.
🎯 Goal: Learn how to use mutate() from the dplyr package in R to add new columns to a data frame.
📋 What You'll Learn
Create a data frame called
sales_data with exact columns and valuesCreate a variable called
high_sales_threshold with a specific numeric valueUse
mutate() to add two new columns: total_revenue and sales_labelPrint the updated
sales_data data frame💡 Why This Matters
🌍 Real World
Adding new columns to data tables is common in business to calculate totals, labels, or categories based on existing data.
💼 Career
Data analysts and scientists often use mutate() in R to prepare and enrich data for reports and decision-making.
Progress0 / 4 steps