Scale a vector so that it sums to some positive number

sum_to(vec, to = 100L)

Arguments

vec

A non-negative integer or numeric vector without NA

to

A positive number

Value

A vector that sums to 'to'

Examples

sum_to(c(1,2,3), 100)
#> [1] 16.66667 33.33333 50.00000