| numbers {essentials} | R Documentation |
Number Vectors
Description
Creates or coerces objects of type “numeric” or “complex”.
is.numbers is a more general test of an object being interpretable as
numbers.
Usage
numbers(length = 0)
as.numbers(x, strict = TRUE, ...)
is.numbers(x)
Arguments
length |
A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error. |
x |
object to be coerced or tested. |
strict |
|
... |
further arguments passed to or from other methods. |
Details
numbers is identical to numeric and
double (and real). It creates a double-precision
vector of the specified length with each element equal to 0.
as.numbers attempts to coerce its argument to be of double or complex
type: like as.vector it strips attributes including names.
is.numbers is a more general test of an object being considered numbers,
meaning the base type of the class is double or integer or
complex and values can reasonably be regarded as numbers (e.g.,
arithmetic on them makes sense, and comparison should be done via the base
type).
Value
for numbers see double.
as.numbers returns either a double or complex vector.
is.numbers(x) is defined as is.numeric(x) ||
is.complex(x).
Examples
x <- 1:5
names(x) <- c("a", "b", "c", "d", "e")
as.numbers(x) # vector converted from integer to double, names removed
x <- x + 0i # x is now a complex vector
as.numbers(x) # vector of type double since all numbers were purely real
## vector of type complex, despite being purely real
as.numbers(x, strict = FALSE)
x <- x + 1i
## vector remains of type complex since numbers are not purely real
as.numbers(x)