Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 68 / 68

[Project] Build a simple inventory system

This lesson covers building a simple inventory system with R's named lists, with the aim of combining what you have learned so far into a larger program.

Combine the lists and loops covered so far into a program that manages stock. A named list looks up and updates values quickly by key — a way of thinking used across all sorts of practical data handling.

The sample code builds a named list for stock with list(apple = 10, orange = 5), reduces the stock with items$apple <- items$apple - 3, and lists every product with a for loop over names(items). Note items[[name]], which reaches a value with a key held in a variable.

A common early stumble is the difference between $ and [[ ]] access. Use $ when you write the key directly and [[ ]] when the key is in a variable.

In professional work, managing data by name or number — inventory, experimental results — is a basic pattern used widely in R data analysis.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)