0
0
R Programmingprogramming~15 mins

Logical indexing in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Logical indexing
📖 Scenario: You are working with a list of daily temperatures recorded in a city. You want to find which days were warm, meaning the temperature was above 20 degrees Celsius.
🎯 Goal: Build a program that uses logical indexing to select only the warm days from the temperature data.
📋 What You'll Learn
Create a numeric vector called temps with the exact values: 18, 22, 19, 25, 21, 17, 23
Create a logical vector called warm_days that is TRUE where temps is greater than 20
Use logical indexing with warm_days to create a vector called warm_temps containing only temperatures above 20
Print the warm_temps vector
💡 Why This Matters
🌍 Real World
Logical indexing is useful when you want to filter data based on conditions, like selecting only warm days from weather data.
💼 Career
Data analysts and scientists often use logical indexing to quickly extract relevant data for reports and decision making.
Progress0 / 4 steps
1
Create the temperature data vector
Create a numeric vector called temps with these exact values: 18, 22, 19, 25, 21, 17, 23
R Programming
Need a hint?

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

2
Create a logical vector for warm days
Create a logical vector called warm_days that is TRUE where temps is greater than 20
R Programming
Need a hint?

Use the comparison operator > to create a logical vector.

3
Select warm temperatures using logical indexing
Use logical indexing with warm_days to create a vector called warm_temps containing only temperatures above 20
R Programming
Need a hint?

Use square brackets [] with the logical vector to select elements.

4
Print the warm temperatures
Write a print statement to display the warm_temps vector
R Programming
Need a hint?

Use the print() function to show the vector.