Get Started

Creating a list

Let us create our first list! To construct a list you use the function list():

my_list <- list(comp1, comp2 ...)

The arguments to the list function are the list components. Remember, these components can be matrices, vectors, other lists, …

This is a part of the course

“Introduction to R”

View Course

Exercise instructions

Construct a list, named my_list, that contains the variables my_vector, my_matrix and my_df as list components.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Vector with numerics from 1 up to 10
my_vector <- 1:10 

# Matrix with numerics from 1 up to 9
my_matrix <- matrix(1:9, ncol = 3)

# First 10 elements of the built-in data frame mtcars
my_df <- mtcars[1:10,]

# Construct list with these different elements:
my_list <-

This exercise is part of the course

Introduction to R

BeginnerSkill Level
4.7+
595 reviews

Master the basics of data analysis in R, including vectors, lists, and data frames, and practice R with real data sets.

As opposed to vectors, lists can hold components of different types, just as your to-do lists can contain different categories of tasks. This chapter will teach you how to create, name, and subset these lists.

Exercise 1: Lists, why would you need them?Exercise 2: Lists, why would you need them? (2)Exercise 3: Creating a list
Exercise 4: Creating a named listExercise 5: Creating a named list (2)Exercise 6: Selecting elements from a listExercise 7: Creating a new list for another movie

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free