msdigit: The most significant digits of numbers

Description Usage Arguments Details Value See Also Examples

View source: R/utils.R

Description

Obtain the most significant digits of numbers in numeric vectors or matrices.

Usage

1

Arguments

x

A numeric vector or matrix.

Details

For each non-zero, non-missing element of x, msdigit returns the first digit of that number's floating point representation of base 10. NA values in x generate NA values in the output of msdigit.

Value

msdigit returns a numeric vector with length equal to the number of non-zero elements of x plus the number of NA values in x.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
msdigit(451)
msdigit(0.00451)
msdigit(-0.00451)
msdigit(c(-31.12, -0.23, 0.1234, 5.32))

x <- c(1, 2, 3, NA)
length(x)
length(msdigit(x)) # equal to length(x)

x <- c(0, 1, 2)
length(x)
length(msdigit(x)) # not equal to length(x)

pedro-teles-fonseca/daubl documentation built on Sept. 24, 2020, 7:31 a.m.