Skip to contents

Returns all non-zero elements of a vector. Zeroness is determined by isZero(), i.e. within a numerical tolerance.

Usage

nz(x, tol = sqrt(.Machine$double.eps))

Arguments

x

a numeric vector.

tol

tolerance passed to isZero().

Value

a vector containing only the non-zero elements of x.

Details

NA elements are not considered zero and are retained in the result.

See also

isZero()

Other vector.utils: unwhich()

Examples

nz(c(0, 1, 2, 0, 3))
#> [1] 1 2 3
nz(c(1e-20, 1, NA))
#> [1]  1 NA