From db75cd35754dafc6e586593690f61b9c8fc00789 Mon Sep 17 00:00:00 2001 From: dchakro <35454738+dchakro@users.noreply.github.com> Date: Sun, 13 Dec 2020 11:29:04 +0200 Subject: [PATCH] roundup Function to round up integer to nearest nth place, e.g. 100th, 10th, 5th. --- roundUp.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 roundUp.R diff --git a/roundUp.R b/roundUp.R new file mode 100644 index 0000000..1fcad31 --- /dev/null +++ b/roundUp.R @@ -0,0 +1,28 @@ +roundUp <- function(x,to=10) +{ +# #<----------------------------> + # # You must include this section when: + # # Distributing, Using and/or Modifying this code. + # # Please read and abide by the terms of the included LICENSE. + # # Copyright 2018, Deepankar Chakroborty, All rights reserved. + + # # Author : Deepankar Chakroborty (https://github.com/dchakro) + # # Report issues: https://github.com/dchakro/shared_Rscripts/issues + # # License: https://github.com/dchakro/shared_Rscripts/blob/master/LICENSE + + # # Adapted from: https://stackoverflow.com/a/44691056 + + # # PURPOSE: + # # This function takes in single number as input and rounds it + # # to the nearest tenth by default. e.g. 7 would be rounded to 10. + + # # PARAMETERS + # # x : The integer to be rounded + # # to: nearest place to round to + + # # EXAMPLES + # roundUp(465,20) would give 480 + # roundUp(462,5) would give 465 + + to*(x%/%to + as.logical(x%%to)) +}