0
0
R Programmingprogramming~30 mins

Nested lists in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Nested Lists in R
📖 Scenario: Imagine you are organizing a small library. Each shelf holds a list of books, and each book has a title and an author. You want to store this information in a nested list in R.
🎯 Goal: Create a nested list in R where each shelf is a list of books, and each book is represented by a list containing its title and author. Then, extract and print the title of the first book on the second shelf.
📋 What You'll Learn
Create a nested list called library with two shelves.
Each shelf should be a list of two books.
Each book should be a list with elements title and author.
Create a variable called first_book_second_shelf to store the title of the first book on the second shelf.
Print the value of first_book_second_shelf.
💡 Why This Matters
🌍 Real World
Nested lists help organize complex data like library catalogs, menus, or survey responses.
💼 Career
Understanding nested data structures is important for data analysis, software development, and managing hierarchical information.
Progress0 / 4 steps
1
Create the nested list library
Create a nested list called library with two shelves. Each shelf should be a list of two books. Each book should be a list with elements title and author. Use these exact values:

First shelf:
- Book 1: title = "The Hobbit", author = "J.R.R. Tolkien"
- Book 2: title = "1984", author = "George Orwell"

Second shelf:
- Book 1: title = "Pride and Prejudice", author = "Jane Austen"
- Book 2: title = "To Kill a Mockingbird", author = "Harper Lee"
R Programming
Need a hint?

Use list() to create lists inside lists. Each shelf is a list of two book lists.

2
Create variable first_book_second_shelf
Create a variable called first_book_second_shelf and assign it the title of the first book on the second shelf from the library nested list.
R Programming
Need a hint?

Use $ and double square brackets [[ ]] to access nested list elements.

3
Print the title stored in first_book_second_shelf
Write a print() statement to display the value of the variable first_book_second_shelf.
R Programming
Need a hint?

Use print() to show the value stored in a variable.

4
Final Output Check
Run the program to print the title of the first book on the second shelf.
R Programming
Need a hint?
The output should be the title of the first book on the second shelf.