0
0
R Programmingprogramming~15 mins

Filtering rows in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Filtering rows
📖 Scenario: You have a small table of fruits with their prices and quantities. You want to find only the fruits that cost more than 2 dollars.
🎯 Goal: Build a program that creates a data frame of fruits, sets a price limit, filters the fruits that cost more than that limit, and prints the filtered data.
📋 What You'll Learn
Create a data frame called fruits with columns name, price, and quantity
Create a variable called price_limit and set it to 2
Filter the fruits data frame to keep only rows where price is greater than price_limit and save it as expensive_fruits
Print the expensive_fruits data frame
💡 Why This Matters
🌍 Real World
Filtering data tables is common when you want to focus on important or relevant information, like finding expensive products in a store.
💼 Career
Data filtering is a key skill in data analysis, reporting, and preparing data for decision making in many jobs.
Progress0 / 4 steps
1
Create the fruits data frame
Create a data frame called fruits with these exact entries: name as c("Apple", "Banana", "Cherry", "Date"), price as c(1.5, 0.5, 3.0, 2.5), and quantity as c(10, 20, 15, 5).
R Programming
Need a hint?

Use the data.frame() function with named vectors for each column.

2
Set the price limit
Create a variable called price_limit and set it to 2.
R Programming
Need a hint?

Just assign the number 2 to the variable price_limit.

3
Filter the fruits by price
Create a new data frame called expensive_fruits that contains only the rows from fruits where the price is greater than price_limit.
R Programming
Need a hint?

Use the square bracket notation with a condition on fruits$price.

4
Print the filtered fruits
Write a print() statement to display the expensive_fruits data frame.
R Programming
Need a hint?

Use print(expensive_fruits) to show the filtered table.