For when you want to rescale a set of numbers to sum to a given value and do not want all rescaled values to be integers.
Examples
x <- rnorm(n = 10, mean = 5, sd = 20)
y <- rescale_integer_sum(x, tot = 10)
#> Error in sample.int(length(x), size, replace, prob): invalid first argument
y
#> Error in eval(expr, envir, enclos): object 'y' not found
sum(y)
#> Error in eval(expr, envir, enclos): object 'y' not found
for(i in 1:10){
y <- rescale_integer_sum(x = rpois(n = 10, lambda = 10), tot = 1000)
print(sum(y))
}
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000
#> [1] 1000