0
0
R Programmingprogramming~15 mins

Vector creation with c() in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Vector creation with c()
📖 Scenario: You are helping a small shop owner organize their daily sales data. They want to keep track of the number of items sold each day in a simple list.
🎯 Goal: Create a vector using the c() function in R to store the number of items sold each day for a week.
📋 What You'll Learn
Create a vector called sales with the exact values: 5, 8, 6, 7, 9, 4, 10
Create a variable called days and set it to 7
Use a for loop with variable i to iterate over the sales vector
Calculate the total sales in a variable called total_sales
Print the total sales using print(total_sales)
💡 Why This Matters
🌍 Real World
Tracking daily sales helps shop owners understand their business performance and plan better.
💼 Career
Data analysts and business managers often work with vectors and loops to process and summarize data.
Progress0 / 4 steps
1
Create the sales vector
Create a vector called sales using the c() function with these exact values: 5, 8, 6, 7, 9, 4, 10
R Programming
Need a hint?

Use the c() function to combine numbers into a vector.

2
Set the number of days
Create a variable called days and set it to 7
R Programming
Need a hint?

Just assign the number 7 to the variable days.

3
Calculate total sales with a loop
Create a variable called total_sales and set it to 0. Then use a for loop with variable i to iterate over the sales vector and add each value to total_sales
R Programming
Need a hint?

Start with total_sales <- 0. Then use for (i in sales) to loop through each number and add it to total_sales.

4
Print the total sales
Write print(total_sales) to display the total number of items sold in the week
R Programming
Need a hint?

Use print(total_sales) to show the result.