Filter Rows in a Data Frame Using filter()
📖 Scenario: You work in a small bookstore and have a list of books with their prices and stock. You want to find which books cost less than $20 to plan a sale.
🎯 Goal: Build a small R program that creates a data frame of books, sets a price limit, filters the books cheaper than that limit using filter(), and prints the filtered list.
📋 What You'll Learn
Create a data frame called
books with columns title, price, and stock with exact valuesCreate a variable called
max_price set to 20Use
dplyr::filter() with books and price < max_price to get cheaper booksPrint the filtered data frame
💡 Why This Matters
🌍 Real World
Filtering data frames is a common task in data analysis to focus on relevant information, like finding affordable products or available stock.
💼 Career
Data analysts and scientists often use filtering to clean and prepare data before making reports or decisions.
Progress0 / 4 steps