length
Length of a Vector or List

Description

Returns a number that describes the length of the object.

Usage

length(x)
length(x) <- value
## S3 method for class 'POSIXlt':
length(x)
lengths(x, use.names = TRUE)

Arguments

x any object.
value an integer.
use.names a logical value. If TRUE (the default), the names of x are copied to the output.

Details

length and length<- are generic functions. Currently there is a length<- method for factors that retains the class and levels attributes.
Value

lengthreturns a number that gives the length of the object (that is, the number of elements in the object). This is normally an integer, but it might be a floating point number if the object is long enough that its length does not fit in an integer.
lengthsreturns a vector of the lengths of the elements of x.
Side Effects
When a value is assigned to the length of an object, then the object is either shortened or lengthened to the new length. Attributes of an object assigned a new length are deleted to avoid the creation of inconsistent data objects. (However, the names attribute of an object is retained, shortened, or lengthened as needed.)
Missing values are placed at the end of a vector that is given a longer length.
See Also
mode, attributes, nchar, ncol, dim, POSIXt.
Examples
z <- list(a=1,b=letters,c=1:5)
length(z) # returns the value 3
length(z$c) # returns the value 5

## POSIXlt (plt <- as.POSIXlt(c("1970-01-01 00:00:00", "2038-01-19 03:14:07"))) length(plt) length(unclass(plt))

lengths(list(1, a=1:3)) # returns c(1L, a=3L) lengths(list(1, a=1:3), use.names=FALSE) # returns c(1L, 3L)

Package base version 6.0.0-69
Package Index