Convert an AnvlArray to a bare R vector.
The array's shape is discarded; the result is always a flat vector.
Each method requires a compatible dtype:
as.double()/as.numeric(): float or (signed/unsigned) integer dtypes.as.integer(): signed or unsigned integer dtypes.as.logical():bool.as.vector(): any dtype; the R type is chosen by the dtype, or forced viamode(e.g."integer","double","logical","list").
Use as_array() to obtain an R array that preserves the shape, or
nv_convert() to change the dtype of an AnvlArray before coercing.
Usage
# S3 method for class 'AnvlArray'
as.double(x, check = FALSE, ...)
# S3 method for class 'AnvlArray'
as.integer(x, check = FALSE, ...)
# S3 method for class 'AnvlArray'
as.logical(x, check = FALSE, ...)
# S3 method for class 'AnvlArray'
as.vector(x, mode = "any")Arguments
- x
(
AnvlArray)
Array to coerce.- check
(
logical(1))
Forwarded toas_array(); see there for details.- ...
Unused.
- mode
(
character(1))
Foras.vector()only. Seebase::as.vector(). Defaults to"any", meaning the natural R type for the array's dtype.
Examples
x <- nv_array(c(1.5, 2.5, 3.5, 4.5), shape = c(2L, 2L))
as.numeric(x)
#> [1] 1.5 2.5 3.5 4.5
as.integer(nv_array(1:6, shape = c(2L, 3L)))
#> [1] 1 2 3 4 5 6
as.logical(nv_array(c(TRUE, FALSE), dtype = "bool"))
#> [1] TRUE FALSE
as.vector(x)
#> [1] 1.5 2.5 3.5 4.5