names
Names Attribute of an Object

Description

Returns or changes the names attribute of an object.

Usage

names(x)
names(x) <- value
## S3 method for class 'POSIXlt':
names(x)
## S3 method for class 'POSIXlt':
names(x) <- value
hasName(x, name)

Arguments

x any object. Typically a list or a vector.
value must be a vector of character strings (or anything that can be coerced to a vector of character strings) that is not longer than x. If the length of value is not as long as x, value is padded with missing values (NA). For any object in x that you do not want to assign a name, you should provide the entry "".

To delete the names attribute explicitly, use names(x) <- NULL.

name a character string or a vector of character stings to look for

Details

On the left side of an assignment, the names attribute of x is set to value.
If x is a matrix or an array, the names assignment produces a warning because matrices and arrays store names in a dimnames attribute. The exception is if x is a single-dimension array: then names and dimnames are equivalent.
To replace row names in a matrix, use rownames or dimnames instead of names.
If you remove the names attribute in the case of a data frame, an illegal data frame is created and some operations fail.
For names.POSIXlt, the year component of the object is named.
If x is an environment, then names(x) returns the names of all of the objects in the environment in no particular order, the same as objects(envir=x, all.names=TRUE, sorted=FALSE). It is an error to use names(x) <- newNames to change the names of the objects in the environment.
Value
returns a character vector the same length as x. If x has a names attribute, this attribute is returned; otherwise, it returns NULL. You can use the names attribute to select subsets and elements. hasName returns a logical value or a vector of logical values. If name is found in the names attribute of the object, TRUE is returned; otherwise, FALSE is returned.
Note
For objects of mode "name", see as.name.
See Also
as.name, attributes, dimnames, rowIds, colnames, rownames, Subscript, POSIXlt
Examples
x <- 1:3

# assign names to a vector names(x) <- c("a", "", "c")

# find the elements of x with non-empty names: x.named <- x[names(x) != ""]

x <- as.POSIXlt(c("1970-01-01 00:00:00", "2038-01-19 03:14:07")) names(x) <- c("Unix Epoch", "Unix Millennium") x

x <- new.env() x$One <- 1 ; x$Two <- 2 ; x$Five <- 5 ; x$.Dotted <- 100 names(x)

x <- c(Jan = 1, Feb = 2, Mar = 3) hasName(x, "Jan")

Package base version 6.1.4-13
Package Index