0
0
R Programmingprogramming~15 mins

Vector indexing (1-based) in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Vector indexing (1-based)
📖 Scenario: You are working with a list of daily temperatures recorded over a week. You want to access specific days' temperatures using their position in the list.
🎯 Goal: Learn how to access elements in a vector using 1-based indexing in R.
📋 What You'll Learn
Create a vector with exact temperature values
Create a variable to hold the index of the day to access
Use vector indexing with the variable to get the temperature
Print the accessed temperature
💡 Why This Matters
🌍 Real World
Accessing specific data points from a list of measurements, like daily temperatures, is common in data analysis and reporting.
💼 Career
Understanding vector indexing is essential for data scientists, statisticians, and anyone working with R for data manipulation.
Progress0 / 4 steps
1
Create the temperature vector
Create a vector called temps with these exact values: 23, 25, 22, 20, 24, 26, 21.
R Programming
Need a hint?

Use the c() function to create a vector with the given numbers.

2
Set the day index
Create a variable called day_index and set it to 3 to represent the third day.
R Programming
Need a hint?

Assign the number 3 to the variable day_index.

3
Access the temperature for the day
Create a variable called temp_for_day that gets the temperature from temps at the position given by day_index using vector indexing.
R Programming
Need a hint?

Use square brackets [] with day_index to get the element from temps.

4
Print the temperature
Print the value of temp_for_day to display the temperature for the third day.
R Programming
Need a hint?

Use the print() function to show the value of temp_for_day.