Skip to contents

mround() is a convenience function I wrote for my annotating bar charts that I make. Assuming a proportion variable, mround() will multiply each value by 100 and round it for presentation. By default, it rounds to two. The user can adjust this.

Usage

mround(x, d = 2)

Arguments

x

a numeric vector

d

the number of decimal points to which the user wants to round. If this is not set, it rounds to two decimal points.

Value

The function takes a numeric vector, multiplies it by 100, rounds it (to two digits by default), and returns it to the user.

Details

This is a sister function of make_perclab() in the same package. This, however, won't add a percentage sign.

Examples


x <- runif(100)
mround(x)
#>   [1] 34.89 86.37 58.20 53.64 35.98 74.72 24.92 85.61 88.11 68.43  2.48 52.25
#>  [13] 42.39 82.85 39.62 34.03 11.33 10.01 14.68 46.77  3.05 21.54 66.47 82.16
#>  [25] 53.00 54.75 33.83  3.01 16.95 32.91 40.37 63.36 23.25 98.01 86.07 58.11
#>  [37] 90.68 15.90 38.91 55.56 89.65 59.78  7.50 70.30 89.77 91.51 29.39 88.11
#>  [49] 17.99 42.67 74.45 48.42 47.87  4.01 94.62 47.39 13.70 40.68  7.62  9.95
#>  [61] 37.42 40.00 86.40 41.31 41.72 52.48 39.81 23.37 12.05 47.92 83.99 87.43
#>  [73] 75.78 68.09  2.67  7.36 20.72 51.21 90.57 98.47 96.65 18.26 36.71 73.81
#>  [85] 33.50 31.90 11.35 20.54 88.47 58.17 96.33  2.00 95.71 13.08  1.90 84.04
#>  [97] 54.51 73.49 60.96 25.37
mround(x, 2) # same as above
#>   [1] 34.89 86.37 58.20 53.64 35.98 74.72 24.92 85.61 88.11 68.43  2.48 52.25
#>  [13] 42.39 82.85 39.62 34.03 11.33 10.01 14.68 46.77  3.05 21.54 66.47 82.16
#>  [25] 53.00 54.75 33.83  3.01 16.95 32.91 40.37 63.36 23.25 98.01 86.07 58.11
#>  [37] 90.68 15.90 38.91 55.56 89.65 59.78  7.50 70.30 89.77 91.51 29.39 88.11
#>  [49] 17.99 42.67 74.45 48.42 47.87  4.01 94.62 47.39 13.70 40.68  7.62  9.95
#>  [61] 37.42 40.00 86.40 41.31 41.72 52.48 39.81 23.37 12.05 47.92 83.99 87.43
#>  [73] 75.78 68.09  2.67  7.36 20.72 51.21 90.57 98.47 96.65 18.26 36.71 73.81
#>  [85] 33.50 31.90 11.35 20.54 88.47 58.17 96.33  2.00 95.71 13.08  1.90 84.04
#>  [97] 54.51 73.49 60.96 25.37
mround(x, 3)
#>   [1] 34.887 86.374 58.199 53.641 35.983 74.722 24.924 85.614 88.110 68.427
#>  [11]  2.478 52.251 42.390 82.849 39.623 34.029 11.333 10.014 14.679 46.768
#>  [21]  3.050 21.542 66.467 82.161 52.996 54.752 33.833  3.013 16.948 32.914
#>  [31] 40.365 63.356 23.249 98.012 86.068 58.109 90.683 15.904 38.909 55.560
#>  [41] 89.648 59.778  7.495 70.304 89.768 91.509 29.390 88.110 17.991 42.672
#>  [51] 74.449 48.418 47.866  4.008 94.620 47.392 13.700 40.677  7.624  9.952
#>  [61] 37.422 40.001 86.398 41.305 41.718 52.483 39.805 23.368 12.049 47.917
#>  [71] 83.986 87.427 75.777 68.087  2.668  7.361 20.718 51.208 90.567 98.470
#>  [81] 96.655 18.262 36.710 73.814 33.502 31.899 11.351 20.539 88.472 58.169
#>  [91] 96.328  2.000 95.713 13.083  1.901 84.042 54.506 73.491 60.958 25.375