This help topic is for R version 1.7.1. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/length.html
length {base}R Documentation

Length of a Vector or List

Description

Get or set the length of vectors (including lists).

Usage

length(x)
length(x) <- n

Arguments

x

a vector or list.

n

an integer.

Details

length is generic: you can write methods to handle of specific classes of objects, see InternalMethods.

The replacement form can be used to reset the length of a vector. If a vector is shortened, extra values are discarded and when a vector is lengthened, it is padded out to its new length with NAs.

Value

The length of x as an integer of length 1, if x is (or can be coerced to) a vector or list. Otherwise, length returns NA.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth \& Brooks/Cole.

Examples

length(diag(4))# = 16 (4 x 4)
length(options())# 12 or more
length(y ~ x1 + x2 + x3)# 3
length(expression(x, {y <- x^2; y+2}, x^y)) # 3

[Package base version 1.7.1 ]