double
Double Precision Objects

Description

Creates or tests for double precision objects.

Usage

double(length = 0L)
is.double(x)
as.double(x, ...)
## S3 method for class 'difftime':
as.double(x, units = "auto", ...)
## S3 method for class 'POSIXlt':
as.double(x, ...)

Arguments

length an integer giving the length of the returned object.
x any object.
units a character string must be one of "auto", "secs", "mins", "hours", "days", and "weeks". By default, is "auto", meaning to use a proper unit.
... additional arguments.

Details

If you want a factor to be treated as numeric, use as.double, as.numeric or as.integer.
You need these functions when you interface to Fortran or C algorithms, where it is important to emphasize the exact storage mode of data.
In most expressions, it is not necessary to ensure explicitly that data are of a particular storage mode. When you test for data suitable for arithmetic, for example, it is better to use is.numeric(x), which returns TRUE for any numeric object. Normally, the engine performs numeric computations with double precision. Explicit reference to storage mode double is usually relevant only when passing arguments to Fortran or C routines that have arguments with double precision or float declarations.
Note the difference between coercing to a vector and setting the storage mode attribute: This changes the storage mode of myobject but leaves all other attributes unchanged (so, for example, a matrix stays a matrix). The value of as.double(myobject) has no attributes.
Value
double returns a simple object of storage mode double, and the length specified.
is.double returns TRUE if x is an object of storage mode double. Otherwise, it returns FALSE.
as.double returns x if x is a simple object of storage mode double. Otherwise, it returns a vector of the same length as x and with data resulting from coercing the elements of x to storage mode double. if x can not be coerced to mode double, NAs will be introduced.
as.double.POSIXlt returns a double object representing the number of seconds since the Unix epoch, i.e., 1970-01-01 00:00:00 GMT.
as.double.difftime returns a double object representing the number of time units.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
.Fortran, mode, numeric, integer, single, vector, POSIXt, difftime
Examples
double(3)
# [1] 0 0 0
storage.mode(1:3)
# [1] "integer"
is.double(1:3)
#[1] FALSE
storage.mode(1)
#[1] "double"
is.double(1)
#[1] TRUE

# POSIXlt plt <- as.POSIXlt(c("1970-01-01 00:00:00", "2038-01-19 03:14:07")) as.double(plt)

# difftime dt <- as.difftime(c("01:00:00", "00:01:00", "00:00:01")) as.double(dt)

Package base version 6.1.4-13
Package Index