
length(x)
length(x) <- value
double
(\href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}MatrixMatrix), even with non-integer values
(earlier versions of \href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}setssets). Where a single double value is
returned that can be represented as an integer it is returned as a
length-one integer vector. As from R 3.0.0, lengths can be returned as double in base R.length<-
has a
"factor"
method. 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 NA
s
(nul
for raw vectors).
Both are primitive functions.
nchar
for counting the number of characters in character
vectors, lengths
for getting the length of every element
in a list.
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
## 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
Run the code above in your browser using DataLab