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] 77.17 86.70  8.91 30.97 62.94 93.54 49.49 18.95 32.14 32.52 58.12 84.82
#>  [13] 67.87 52.93 22.46 68.72 14.33 24.87 39.63 61.16  4.70 34.00 60.88  5.18
#>  [25] 29.85 34.66 87.61 41.54 76.29 22.50 66.38 40.79 41.30 67.60 95.44 27.72
#>  [37] 45.55 16.41 15.38  7.23 93.26 31.99 24.51 53.31 91.62 22.81 12.14 34.06
#>  [49] 61.89 85.55 65.54 60.79 49.81 65.56 88.59 26.24 72.44 22.17 31.03 15.95
#>  [61] 74.47 83.76 77.94 75.31 23.87 59.91 24.03 64.50 80.73 80.78 31.72 34.27
#>  [73] 47.95  3.81 51.50  3.64 47.21  2.44 31.31 72.60 24.25 95.20  4.47 57.24
#>  [85] 83.92 96.72 16.90 25.97 30.70 73.46 43.82 85.82 87.88 26.51 70.31 30.54
#>  [97] 90.63  6.73 60.41 15.60
mround(x, 2) # same as above
#>   [1] 77.17 86.70  8.91 30.97 62.94 93.54 49.49 18.95 32.14 32.52 58.12 84.82
#>  [13] 67.87 52.93 22.46 68.72 14.33 24.87 39.63 61.16  4.70 34.00 60.88  5.18
#>  [25] 29.85 34.66 87.61 41.54 76.29 22.50 66.38 40.79 41.30 67.60 95.44 27.72
#>  [37] 45.55 16.41 15.38  7.23 93.26 31.99 24.51 53.31 91.62 22.81 12.14 34.06
#>  [49] 61.89 85.55 65.54 60.79 49.81 65.56 88.59 26.24 72.44 22.17 31.03 15.95
#>  [61] 74.47 83.76 77.94 75.31 23.87 59.91 24.03 64.50 80.73 80.78 31.72 34.27
#>  [73] 47.95  3.81 51.50  3.64 47.21  2.44 31.31 72.60 24.25 95.20  4.47 57.24
#>  [85] 83.92 96.72 16.90 25.97 30.70 73.46 43.82 85.82 87.88 26.51 70.31 30.54
#>  [97] 90.63  6.73 60.41 15.60
mround(x, 3)
#>   [1] 77.172 86.698  8.905 30.967 62.935 93.542 49.492 18.947 32.144 32.524
#>  [11] 58.119 84.819 67.867 52.925 22.461 68.724 14.332 24.873 39.633 61.155
#>  [21]  4.699 33.996 60.877  5.179 29.851 34.662 87.609 41.538 76.293 22.500
#>  [31] 66.381 40.790 41.301 67.601 95.436 27.716 45.554 16.414 15.384  7.225
#>  [41] 93.260 31.993 24.513 53.315 91.617 22.808 12.136 34.064 61.887 85.549
#>  [51] 65.538 60.786 49.807 65.555 88.587 26.241 72.441 22.170 31.025 15.948
#>  [61] 74.472 83.756 77.942 75.306 23.872 59.912 24.030 64.500 80.728 80.779
#>  [71] 31.717 34.270 47.949  3.805 51.502  3.644 47.212  2.442 31.313 72.599
#>  [81] 24.251 95.197  4.468 57.236 83.924 96.723 16.904 25.972 30.699 73.460
#>  [91] 43.823 85.825 87.883 26.506 70.314 30.537 90.630  6.727 60.409 15.596