Using a For Loop in R
📖 Scenario: You work in a small bakery and want to calculate the total number of cookies sold in a week. You have the daily sales numbers and want to add them up.
🎯 Goal: Build a simple R program that uses a for loop to sum daily cookie sales and print the total.
📋 What You'll Learn
Create a vector called
daily_sales with the exact values: 12, 15, 10, 20, 18, 25, 22Create a variable called
total_sales and set it to 0Use a
for loop with the variable sales to iterate over daily_salesAdd each
sales value to total_sales inside the loopPrint the value of
total_sales💡 Why This Matters
🌍 Real World
Summing daily sales is a common task in small businesses to track performance over time.
💼 Career
Understanding loops and data aggregation is essential for data analysis and reporting roles.
Progress0 / 4 steps