Sorting a List of Fruits by Price Using order() in R
📖 Scenario: You run a small fruit shop and keep a list of fruits with their prices. You want to sort the fruits by their prices to decide which ones to promote.
🎯 Goal: Learn how to use the order() function in R to sort a list of fruits by their prices in ascending order.
📋 What You'll Learn
Create a vector called
fruits with the values "apple", "banana", "cherry", "date", "elderberry"Create a numeric vector called
prices with the values 3.5, 2.0, 4.0, 5.5, 1.5Create a variable called
sorted_indices using the order() function on pricesUse
sorted_indices to create a new vector called sorted_fruits that sorts fruits by pricePrint the
sorted_fruits vector💡 Why This Matters
🌍 Real World
Sorting items by price helps shop owners decide which products to promote or discount.
💼 Career
Understanding sorting techniques is essential for data analysis and organizing information efficiently in many jobs.
Progress0 / 4 steps