Learn R Programming

gmp (version 0.5-4)

asNumeric: Coerce to 'numeric', not Loosing Dimensions

Description

a number-like object is coerced to type (typeof) "numeric", keeping dim (and maybe dimnames) when present.

Usage

asNumeric(x)

Arguments

x
a number-like object, e.g., big integer (bigz), or mpfr, notably including matrices and arrays of such numbers.

Value

See Also

as.numeric coerces to both "numeric" and to a vector, whereas asNumeric() should keep dim (and other) attributes.

Examples

Run this code
m <- matrix(1:6, 2,3)
stopifnot(identical(m, asNumeric(m)))# remains matrix

(M <- as.bigz(m) / 5) ##-> "bigq" matrix
asNumeric(M) # numeric matrix
stopifnot(all.equal(asNumeric(M), m/5))

Run the code above in your browser using DataLab