# Basic usage
txtRound(1.023, digits = 1)
# > "1.0"
txtRound(pi, digits = 2)
# > "3.14"
txtRound(12344, digits = 1, txtInt_args = TRUE)
# > "12,344.0"
# Using matrix
mx <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE)
txtRound(mx, digits = 1)
#> [,1] [,2] [,3]
#> [1,] "1.0" "1.1" "1.2"
#> [2,] "2.5" "2.5" "2.5"
#> [3,] "3.2" "3.0" "3.1"
# Using a data.frame directly
library(magrittr)
data("mtcars")
# If we want to round all the numerical values
mtcars %>%
txtRound(digits = 1)
# If we want only want to round some columns
mtcars %>%
txtRound(wt, qsec_txt = qsec, digits = 1)
Run the code above in your browser using DataLab