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, 23Create a logical vector called
warm_days that is TRUE where temps is greater than 20Use logical indexing with
warm_days to create a vector called warm_temps containing only temperatures above 20Print 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