Created
November 2, 2018 20:23
-
-
Save chadsten/5445c9bd132886461f8e59c8ea3f194d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pum_mod2 <- function(conv_factor, value) { | |
mod <- 0 | |
case_when( | |
value < conv_factor ~ mod <- ceiling(conv_factor - value), | |
value %% conv_factor != 0 ~ mod <- ceiling((value / conv_factor) * conv_factor - value), | |
) | |
return(mod) | |
} | |
pum_mod <- function(conv_factor, value) { | |
# for values smaller than the conversion factor, we just need add the difference | |
if (value < conv_factor) { | |
mod <- ceiling(conv_factor - value) | |
# for values larger than the conversion factor, we calc the remainder to get up to a number that is evenly divisible | |
} else if ((value %% conv_factor) != '0') { | |
mod <- ceiling((value / conv_factor) * conv_factor - value) | |
} else { | |
mod <- 0 | |
} | |
return(mod) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment