Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Labeling List Elements | Lists
R Introduction

bookLabeling List Elements

List elements can be given labels to make them easier to identify and work with.

Assigning Labels on List Creation

To assign labels during the list creation, use the syntax name = value (without quotes around the name) in the list() function.

Example

12
test <- list(text = "Text", number = 42, logical = TRUE) test
copy

Assigning Labels to an Existing List

If the list is already created, you can add labels afterward by assigning a vector of labels to names(list).

Example

123
test <- list("Text", 42, TRUE) names(test) <- c('text', 'number', 'logical') test
copy
Task

Swipe to start coding

You have a list info with course information.

Your task is to:

  1. Use the names() function to assign the following names to its elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'.
  2. Output the resulting list.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 6. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 2.27

bookLabeling List Elements

Swipe to show menu

List elements can be given labels to make them easier to identify and work with.

Assigning Labels on List Creation

To assign labels during the list creation, use the syntax name = value (without quotes around the name) in the list() function.

Example

12
test <- list(text = "Text", number = 42, logical = TRUE) test
copy

Assigning Labels to an Existing List

If the list is already created, you can add labels afterward by assigning a vector of labels to names(list).

Example

123
test <- list("Text", 42, TRUE) names(test) <- c('text', 'number', 'logical') test
copy
Task

Swipe to start coding

You have a list info with course information.

Your task is to:

  1. Use the names() function to assign the following names to its elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'.
  2. Output the resulting list.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 6. ChapterΒ 2
single

single

some-alt