Generate a table of places (by power of 10, with column names such as "10^2" and "10^-2") from a vector of numeric values.
Usage
splitByPlace(
x,
max_power_10 = 2,
min_power_10 = -2,
x_arg = rlang::caller_arg(x),
call = rlang::caller_env()
)Arguments
- x
numericA vector of values to evaluate.- max_power_10
integerThe highest 10s place to check, as a power of 10.- min_power_10
integerThe lowest 10s place to check, as a power of 10. Must be lower thanmax_power_10.- x_arg
characterThe name ofxto use in the output table and error messages. By default this is automatically determined from the calling context, and you can likely leave it as-is.- call
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See thecallargument ofabort()for more information.
Value
A tibble::tibble() with a column for the original vector (named
using x_arg) and columns for each power of 10 between max_power_10 and
min_power_10.
Examples
random_data <- runif(10, 0, 1000)
splitByPlace(random_data)
#> # A tibble: 10 × 6
#> random_data `10^2` `10^1` `10^0` `10^-1` `10^-2`
#> <dbl> <int> <int> <int> <int> <int>
#> 1 257.949 2 5 7 9 4
#> 2 863.889 8 6 3 8 8
#> 3 664.232 6 6 4 2 3
#> 4 199.325 1 9 9 3 2
#> 5 518.763 5 1 8 7 6
#> 6 443.291 4 4 3 2 9
#> 7 99.388 NA 9 9 3 8
#> 8 981.610 9 8 1 6 0
#> 9 518.159 5 1 8 1 5
#> 10 707.356 7 0 7 3 5
splitByPlace(random_data, 2, -5)
#> # A tibble: 10 × 9
#> random_data `10^2` `10^1` `10^0` `10^-1` `10^-2` `10^-3` `10^-4` `10^-5`
#> <dbl> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 257.949271 2 5 7 9 4 9 2 7
#> 2 863.888566 8 6 3 8 8 8 5 6
#> 3 664.232024 6 6 4 2 3 2 0 2
#> 4 199.324574 1 9 9 3 2 4 5 7
#> 5 518.763204 5 1 8 7 6 3 2 0
#> 6 443.291329 4 4 3 2 9 1 3 2
#> 7 99.388438 NA 9 9 3 8 8 4 3
#> 8 981.609734 9 8 1 6 0 9 7 3
#> 9 518.158503 5 1 8 1 5 8 5 0
#> 10 707.355550 7 0 7 3 5 5 5 5
splitByPlace(random_data, 2, -5, "measurements")
#> # A tibble: 10 × 9
#> measurements `10^2` `10^1` `10^0` `10^-1` `10^-2` `10^-3` `10^-4` `10^-5`
#> <dbl> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 257.949271 2 5 7 9 4 9 2 7
#> 2 863.888566 8 6 3 8 8 8 5 6
#> 3 664.232024 6 6 4 2 3 2 0 2
#> 4 199.324574 1 9 9 3 2 4 5 7
#> 5 518.763204 5 1 8 7 6 3 2 0
#> 6 443.291329 4 4 3 2 9 1 3 2
#> 7 99.388438 NA 9 9 3 8 8 4 3
#> 8 981.609734 9 8 1 6 0 9 7 3
#> 9 518.158503 5 1 8 1 5 8 5 0
#> 10 707.355550 7 0 7 3 5 5 5 5