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

Structured data with lists

This lesson covers handling structured data with R's list, with the aim of managing different kinds of data together.

list() creates a list, which gathers several named pieces of data. Unlike a vector, it can hold values of different types in one place.

The sample code builds a list with animal <- list(name = "Dog", sound = "Woof") and reaches its properties with the $ symbol, as in animal$name. It is a flexible mechanism that lets you gather data much like an object.

A common early stumble is the difference between a vector and a list. A vector holds only one type; a list can freely mix strings and numbers.

In professional work, lists are used whenever you want to handle data with several attributes together — one customer's details, for instance.

๐Ÿ“– 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)