Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Namings | Lists
R Introduction: Part II
course content

Contenido del Curso

R Introduction: Part II

R Introduction: Part II

1. Matrices
2. Data Frames
3. Lists

bookNamings

In the previous chapter, you saw that list output contains indices within double square brackets. That's good, but wouldn't it be better if we had names instead of indices? Indeed, it would.

There are two ways to set names on list elements. The first is used in the process of list creation. Within list() function use name = values equalities (name should be used without quotes). For example, let's rewrite the previous example with names.

1234
# Creating a list test <- list(text = "Text", number = 42, logical = TRUE) # Output list value test
copy

That's much better! The second way is to set names for the already created list. Assign a vector of names to names(list) function. For example,

123456
# Creating a list test <- list("Text", 42, TRUE) # Setting names to elements names(test) <- c('text', 'number', 'logical') # Output list value test
copy
Tarea
test

Swipe to show code editor

Given the list info from the previous chapter. Using the second method (names() function), assign the following names to elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'. Output the list, then.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
toggle bottom row

bookNamings

In the previous chapter, you saw that list output contains indices within double square brackets. That's good, but wouldn't it be better if we had names instead of indices? Indeed, it would.

There are two ways to set names on list elements. The first is used in the process of list creation. Within list() function use name = values equalities (name should be used without quotes). For example, let's rewrite the previous example with names.

1234
# Creating a list test <- list(text = "Text", number = 42, logical = TRUE) # Output list value test
copy

That's much better! The second way is to set names for the already created list. Assign a vector of names to names(list) function. For example,

123456
# Creating a list test <- list("Text", 42, TRUE) # Setting names to elements names(test) <- c('text', 'number', 'logical') # Output list value test
copy
Tarea
test

Swipe to show code editor

Given the list info from the previous chapter. Using the second method (names() function), assign the following names to elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'. Output the list, then.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
toggle bottom row

bookNamings

In the previous chapter, you saw that list output contains indices within double square brackets. That's good, but wouldn't it be better if we had names instead of indices? Indeed, it would.

There are two ways to set names on list elements. The first is used in the process of list creation. Within list() function use name = values equalities (name should be used without quotes). For example, let's rewrite the previous example with names.

1234
# Creating a list test <- list(text = "Text", number = 42, logical = TRUE) # Output list value test
copy

That's much better! The second way is to set names for the already created list. Assign a vector of names to names(list) function. For example,

123456
# Creating a list test <- list("Text", 42, TRUE) # Setting names to elements names(test) <- c('text', 'number', 'logical') # Output list value test
copy
Tarea
test

Swipe to show code editor

Given the list info from the previous chapter. Using the second method (names() function), assign the following names to elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'. Output the list, then.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

In the previous chapter, you saw that list output contains indices within double square brackets. That's good, but wouldn't it be better if we had names instead of indices? Indeed, it would.

There are two ways to set names on list elements. The first is used in the process of list creation. Within list() function use name = values equalities (name should be used without quotes). For example, let's rewrite the previous example with names.

1234
# Creating a list test <- list(text = "Text", number = 42, logical = TRUE) # Output list value test
copy

That's much better! The second way is to set names for the already created list. Assign a vector of names to names(list) function. For example,

123456
# Creating a list test <- list("Text", 42, TRUE) # Setting names to elements names(test) <- c('text', 'number', 'logical') # Output list value test
copy
Tarea
test

Swipe to show code editor

Given the list info from the previous chapter. Using the second method (names() function), assign the following names to elements: 'Course name', 'Section', 'Chapter', 'Chapter overall'. Output the list, then.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 2
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt