as.scalar {essentials} | R Documentation |
Scalars
Description
Coerce objects to scalars (vectors of length 1).
Usage
as.scalar(x)
as.scalar.logical(x)
as.scalar.integer(x)
as.scalar.real(x)
as.scalar.double(x)
as.scalar.numeric(x)
as.scalar.complex(x)
as.scalar.number(x, strict = TRUE)
as.scalar.string(x)
as.scalar.character(x)
Arguments
x |
object to be coerced. |
strict |
|
Details
as.scalar.logical
coerces an object to a vector of type “logical”
of length 1.
as.scalar.integer
coerces an object to a vector of type “integer”
of length 1.
as.scalar.real
, as.scalar.double
and as.scalar.numeric
coerces an object to a vector of type “numeric” of length 1.
as.scalar.complex
coerces an object to a vector of type “complex”
of length 1.
as.scalar.number
coerces an object to a vector of type “numeric”
or “complex” of length 1.
as.scalar.string
and as.scalar.character
coerces an object to a
vector of type “character” of length 1.
as.scalar
coerces an object to a vector of length 1.
Value
a vector of length 1
Examples
## if the type converting from and converting to are identical, as.scalar is a
## much shorter way of writing what you intend.
as.scalar(c(TRUE, FALSE, NA))
as.scalar(1:100)
as.scalar(1:10 + 0.5)
as.scalar(exp((0+1i) * 6 * (-4:4)))
as.scalar(letters)
## if the type converting from and converting to are not identical, it is better
## to specify the type converting to.
as.scalar.logical(c(TRUE, FALSE, NA))
as.scalar.integer(c(TRUE, FALSE, NA))
as.scalar.numeric(c(TRUE, FALSE, NA))
as.scalar.complex(c(TRUE, FALSE, NA))
as.scalar.character(c(TRUE, FALSE, NA))