从 R 中的数字中提取第一个非零数字

O. *_*ity 2 r extract numeric

有没有办法可以提取 R 中数值的第一个非零数字?

示例输入:

123.01, 0.56, 0.078, 0.0092
Run Code Online (Sandbox Code Playgroud)

输出:

1, 5, 7, 9
Run Code Online (Sandbox Code Playgroud)

Hen*_*nry 7

这适用于正输入:

firstdigit <- function(x){ floor(x / 10 ^ floor(log10(x))) }
firstdigit(c(123.01, 0.56, 0.078, 0.0092))
# 1 5 7 9
Run Code Online (Sandbox Code Playgroud)