Using lapply and sapply in R
📖 Scenario: You are working with a list of numeric vectors representing daily sales for different stores. You want to calculate the total sales and average sales for each store using R.
🎯 Goal: Build a small R script that uses lapply and sapply to calculate total and average sales for each store from a list of sales data.
📋 What You'll Learn
Create a list called
store_sales with three numeric vectors named store1, store2, and store3 with exact valuesCreate a variable called
sales_threshold set to 100Use
lapply to calculate total sales for each storeUse
sapply to calculate average sales for each storePrint the total sales list and average sales vector
💡 Why This Matters
🌍 Real World
Analyzing sales data from multiple stores to quickly calculate totals and averages helps businesses make informed decisions.
💼 Career
Data analysts and R programmers often use <code>lapply</code> and <code>sapply</code> to efficiently process lists of data without writing loops.
Progress0 / 4 steps