Function used to rescale a vector to a given value. This is a frequently needed operation.

rescale_vector(x, scale = 1)

Arguments

x

numeric vector.

scale

numeric. Value the vector should sum to. Default 1.

Value

The vector rescaled.

Details

For a distribution, use scale = 1. For percentages, use scale = 100, etc.

Examples

x <- runif(10) sum(x)
#> [1] 4.638806
xx <- rescale_vector(x,100) sum(xx)
#> [1] 100