Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

length: Length of an Object

lengthR Documentation

Length of an Object

Description

Get or set the length of vectors (including lists) and factors, and ofany otherR object for which a method has been defined.

Usage

length(x)length(x) <- value

Arguments

x

anR object. For replacement, a vector or factor.

value

a non-negative integer or double (which will be rounded down).

Details

Both functions are generic: you can write methods to handle specificclasses of objects, see InternalMethods.length<- has a"factor" method.

The replacement form can be used to reset the length of a vector. Ifa vector is shortened, extra values are discarded and when a vector islengthened, it is padded out to its new length withNAs(nul for raw vectors).

Both are primitive functions.

Value

The default method forlength currently returns a non-negativeinteger of length 1, except for vectors of more than2^31 - 1 elements, when it returns a double.

For vectors (including lists) and factors the length is the number ofelements. For an environment it is the number of objects in theenvironment, andNULL has length 0. For expressions andpairlists (including language objects and dotlists) it is thelength of the pairlist chain. All other objects (including functions)have length one: note that for functions this differs from S.

The replacement form removes all the attributes ofx except itsnames, which are adjusted (and if necessary extended by"").

Warning

Package authors have written methods that return a result of lengthother than one (Formula) and that return a vector of typedouble (Matrix), even with non-integer values(earlier versions ofsets). Where a single double value isreturned that can be represented as an integer it is returned as alength-one integer vector.

References

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

See Also

nchar for counting the number of characters in charactervectors,lengths for getting the length of every elementin a list.

Examples

length(diag(4))  # = 16 (4 x 4)length(options())  # 12 or morelength(y ~ x1 + x2 + x3)  # 3length(expression(x, {y <- x^2; y+2}, x^y))  # 3## from example(warpbreaks)require(stats)fm1 <- lm(breaks ~ wool * tension, data = warpbreaks)length(fm1$call)      # 3, lm() and two arguments.length(formula(fm1))  # 3, ~ lhs rhs

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp