How to Apply the names() Function in R (Example Code)

In this R post you’ll learn how to get or set the names of a data object.

Creation of Example Data

example_vector <- LETTERS[1:4]                          # Creating example data
example_vector
# "A" "B" "C" "D"
example_names <- c("name1", "name2", "name3", "name4")  # Some names
example_names
# "name1" "name2" "name3" "name4"

Example: Created Named Vector in R

names(example_vector) <- example_names                  # Apply names function
example_vector                                          # Final result
# name1 name2 name3 name4 
#   "A"   "B"   "C"   "D"

Leave a Reply

Your email address will not be published.

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