0
0
R Programmingprogramming~15 mins

Named list elements in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Named list elements
📖 Scenario: Imagine you are organizing a small collection of fruits with their quantities. You want to keep track of each fruit by name and how many you have.
🎯 Goal: You will create a named list in R where each fruit name is linked to its quantity. Then you will access and display this information.
📋 What You'll Learn
Create a named list with exact fruit names and quantities
Create a variable to hold the name of a fruit to look up
Use the variable to get the quantity from the named list
Print the quantity of the chosen fruit
💡 Why This Matters
🌍 Real World
Named lists help organize data by labels, like keeping track of items and their counts in a store or kitchen.
💼 Career
Understanding named lists is useful for data analysis, reporting, and programming tasks where you need to label and access data clearly.
Progress0 / 4 steps
1
Create a named list of fruits
Create a named list called fruits with these exact entries: apple = 5, banana = 3, orange = 7
R Programming
Need a hint?

Use the list() function with names and values separated by =.

2
Create a variable for the fruit name
Create a variable called chosen_fruit and set it to the string "banana"
R Programming
Need a hint?

Use the assignment operator <- to assign the string "banana" to chosen_fruit.

3
Get the quantity of the chosen fruit
Create a variable called quantity that gets the value from fruits using the name stored in chosen_fruit
R Programming
Need a hint?

Use double square brackets [[ ]] with the variable chosen_fruit to access the list element.

4
Print the quantity
Write a print() statement to display the value of quantity
R Programming
Need a hint?

Use print(quantity) to show the number.