rescale_vector: Rescale a vector proportionally to a new sum.

View source: R/utils.R

rescale_vectorR Documentation

Rescale a vector proportionally to a new sum.

Description

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

Usage

rescale_vector(x, scale = 1)

Arguments

x

numeric vector.

scale

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

Details

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

Value

The vector rescaled.

Examples

x <- runif(10)
sum(x)
xx <- rescale_vector(x,100)
sum(xx)

timriffe/DemoTools documentation built on Oct. 14, 2024, 12:53 p.m.