0
0
R Programmingprogramming~30 mins

summarise() with group_by() in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Summarise Data with group_by() in R
📖 Scenario: You have sales data from a small store. Each sale has a product name and the number of units sold. You want to find out how many units were sold for each product in total.
🎯 Goal: Build a small R script that groups sales by product and calculates the total units sold for each product using group_by() and summarise().
📋 What You'll Learn
Create a data frame called sales with columns product and units with exact values
Create a grouped data frame using group_by() on product
Use summarise() to calculate total units sold per product
Print the summarised data frame
💡 Why This Matters
🌍 Real World
Stores and businesses often need to summarise sales data by product to understand which items sell the most.
💼 Career
Data analysts and scientists use <code>dplyr</code> functions like <code>group_by()</code> and <code>summarise()</code> to prepare and analyse data efficiently.
Progress0 / 4 steps
1
Create the sales data frame
Create a data frame called sales with two columns: product and units. Use these exact values: product = c("apple", "banana", "apple", "orange", "banana"), units = c(5, 3, 2, 4, 1).
R Programming
Need a hint?

Use data.frame() with named vectors for product and units.

2
Group sales by product
Load the dplyr package with library(dplyr). Then create a new variable called grouped_sales by applying group_by() on the sales data frame grouping by product.
R Programming
Need a hint?

Use library(dplyr) to load the package first.

3
Summarise total units sold per product
Create a new variable called summary_sales by applying summarise() on grouped_sales. Calculate the total units sold per product using total_units = sum(units).
R Programming
Need a hint?

Use summarise() with total_units = sum(units) inside.

4
Print the summarised sales data
Print the summary_sales data frame to show total units sold per product.
R Programming
Need a hint?

Use print(summary_sales) to display the result.