Apply functions on matrices
📖 Scenario: You work in a small bakery that tracks daily sales of different types of bread in a matrix. Each row represents a day, and each column represents a bread type.You want to analyze the sales data by applying functions to the matrix rows and columns.
🎯 Goal: Build an R program that creates a sales matrix, sets a threshold for good sales, applies functions to calculate total sales per day and average sales per bread type, and prints the results.
📋 What You'll Learn
Create a matrix called
sales with 3 rows and 4 columns using the exact values: 10, 15, 20, 25, 5, 10, 15, 20, 0, 5, 10, 15Create a variable called
good_sales_threshold and set it to 15Use
apply() to calculate total sales per day (sum of each row) and store it in total_sales_per_dayUse
apply() to calculate average sales per bread type (mean of each column) and store it in average_sales_per_breadPrint
total_sales_per_day and average_sales_per_bread💡 Why This Matters
🌍 Real World
Analyzing sales data in a bakery or any small business helps understand daily performance and product popularity.
💼 Career
Data analysts and business managers often use matrix operations and apply functions to summarize and interpret data efficiently.
Progress0 / 4 steps