x <- c(pi, exp(1))
x <- c(x, x*10, x*100, x*1000)
# make one specification using each rounding approach
specs <- list(
magnitude = round_using_magnitude(round_spec()),
decimal = round_using_decimal(round_spec()),
signif = round_using_signif(round_spec())
)
# apply all three rounding specifications to x
# notice how the rounding specifications are in agreement
# for smaller values of x but their answers are different
# for larger values of x.
sapply(specs, function(rspec) table_value(x, rspec))
# output:
# magnitude decimal signif
# [1,] "3.1" "3.1" "3.1"
# [2,] "2.7" "2.7" "2.7"
# [3,] "31" "31.4" "31.0"
# [4,] "27" "27.2" "27.0"
# [5,] "314" "314.2" "310.0"
# [6,] "272" "271.8" "270.0"
# [7,] "3,142" "3,141.6" "3,100.0"
# [8,] "2,718" "2,718.3" "2,700.0"
Run the code above in your browser using DataLab