View source: R/sequence_characteristics.R
scale_rounded_by_sum | R Documentation |
Scale values so that the rounded values sum to 1
scale_rounded_by_sum(
x,
digits,
icolumn_adjust = 1L,
max_iter = max(4L, digits + 1L),
verbose = FALSE
)
x |
A one or two-dimensional numeric object with positive values: a vector, data frame, matrix, or array. A vector is treated as a 1-row matrix. |
digits |
A integer value. The number of decimal places to round; a number between one and four. |
icolumn_adjust |
An integer value. The column number of
|
max_iter |
An integer value. The maximum number of iterations. |
verbose |
A logical value. Reports a warning if |
This function may fail due to integer division by zero.
This function may also not converge to round values so that they sum to 1,
particularly if too few digits
are available to round. In that case,
attempt to increase digits
. However, the return values should sum
to within digits
of 1.
scale_by_sum
, round
x <- c(1:6, 8) / 10
scale_rounded_by_sum(x, digits = 1, icolumn_adjust = 7)
scale_rounded_by_sum(x, digits = 2, icolumn_adjust = 7)
scale_rounded_by_sum(x, digits = 4, icolumn_adjust = 7)
x <- matrix(1:12, nrow = 4, ncol = 3)
scale_rounded_by_sum(x, digits = 1)
scale_rounded_by_sum(x, digits = 2)
scale_rounded_by_sum(x, digits = 4)
x <- as.data.frame(x)
scale_rounded_by_sum(x, digits = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.