0
0
R Programmingprogramming~15 mins

Comparison operators in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Comparison Operators in R
📖 Scenario: You are working in a small shop and want to check which products are priced above a certain amount to decide which ones to promote.
🎯 Goal: Build a simple R program that uses comparison operators to find products priced above a threshold.
📋 What You'll Learn
Create a named numeric vector called products with exact product names and prices
Create a numeric variable called threshold with the value 50
Use a comparison operator to create a logical vector called expensive_products that is TRUE for products priced above threshold
Print the expensive_products vector
💡 Why This Matters
🌍 Real World
Shops often need to filter products by price to decide which items to promote or discount.
💼 Career
Understanding comparison operators is essential for data filtering and decision making in data analysis and programming jobs.
Progress0 / 4 steps
1
Create the products vector
Create a named numeric vector called products with these exact entries: apple = 30, banana = 20, cherry = 60, date = 80, elderberry = 40.
R Programming
Need a hint?

Use the c() function with named elements like name = value.

2
Set the price threshold
Create a numeric variable called threshold and set it to 50.
R Programming
Need a hint?

Just assign the number 50 to the variable threshold.

3
Find products priced above the threshold
Use the greater than operator > to create a logical vector called expensive_products that is TRUE for products priced above threshold.
R Programming
Need a hint?

Use products > threshold to get TRUE or FALSE for each product.

4
Print the result
Print the expensive_products vector to see which products are above the threshold.
R Programming
Need a hint?

Use print(expensive_products) to show the logical vector.