We use the names()
function in R to obtain or set the name of an R object.
The syntax for the names()
function is given below:
names(x)names(x) <- value
The names()
function takes the following parameter values:
x
: This is an R object.value
: This represents a character vector having the same length as x
.# creating an R objectmylist <- list(length = 10, height = 5, breadth = 2)# to obtain the names of the listnames(mylist)
list()
function to create an R object that is mylist
.names()
function to obtain the names of the object, mylist
.# creating an R objecta <- 1:5# setting names to the objectnames(a) <- c("one", "two", "three", "four", "five")# to show the modified objecta
a
.names()
function.