How to Get Names of List Objects in R (Example Code)

In this tutorial you’ll learn how to get the names of list elements in the R programming language.

Introducing Example Data

example_list <- list(A = LETTERS[1:3],    # Constructing example list
                     B = 1:7,
                     C = letters[8:2],
                     D = 555)
example_list                              # Showing list in RStudio console
# $A
# [1] "A" "B" "C"
# 
# $B
# [1] 1 2 3 4 5 6 7
# 
# $C
# [1] "h" "g" "f" "e" "d" "c" "b"
# 
# $D
# [1] 555
#

Example: Extract Names of All List Elements

names(example_list)                       # Returning names of list objects
# [1] "A" "B" "C" "D"

Further Resources & Related Articles

In the following, you may find some further resources on topics such as data elements, loops, extracting data, and lists:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top