Useful vector functions (length, sum, mean)
📖 Scenario: You are working with a list of daily sales numbers for a small shop. You want to learn how to use basic R functions to find out how many days you have data for, the total sales, and the average sales per day.
🎯 Goal: Build a simple R script that uses the length(), sum(), and mean() functions on a vector of sales numbers to get useful information.
📋 What You'll Learn
Create a numeric vector called
sales with exact values: 150, 200, 175, 300, 225Create a variable called
total_days that stores the length of the sales vector using length()Create a variable called
total_sales that stores the sum of the sales vector using sum()Create a variable called
average_sales that stores the mean of the sales vector using mean()Print the values of
total_days, total_sales, and average_sales each on its own line💡 Why This Matters
🌍 Real World
Small business owners often track daily sales to understand their performance. Using R functions like length, sum, and mean helps quickly summarize sales data.
💼 Career
Data analysts and business intelligence professionals use these basic vector functions to prepare and analyze data before creating reports or visualizations.
Progress0 / 4 steps