Skip to contents

stm_round() rounds numeric data to a specified number of digits. If the input is a list, the rounding is applied element-wise to each numeric element.

Usage

stm_round(dat, digits = NULL)

Arguments

dat

A numeric vector, list, or matrix to round.

digits

Optional. The number of decimal places to round to. If not provided or invalid, the original data is returned.

Value

The rounded data.

Details

The function applies rounding to numeric data. If dat is a list, it will apply rounding element-wise to each numeric element in the list. If an error occurs during rounding, the original data is returned.

Examples

stm_round(3.14159, digits = 2)
#> [1] 3.14
stm_round(3.14159, digits = "two")
#> [1] 3.14159
a <- list(3.14159, "hello", 2.71828, list(1.61803, "world"))
stm_round(a, digits = 3)
#> [[1]]
#> [1] 3.142
#> 
#> [[2]]
#> [1] "hello"
#> 
#> [[3]]
#> [1] 2.718
#> 
#> [[4]]
#> [[4]][[1]]
#> [1] 1.61803
#> 
#> [[4]][[2]]
#> [1] "world"
#> 
#>