Description Usage Arguments Details Value Transformation based on specific columns Examples
This was for two reasons: (1) to avoid the (more commonly used)
t(scale(t(x), ...)
idiom; and (2) to specify what values, columns of x,
etc. to use to calculate means and sd's to use in the scaling function.
1 | scale_rows(x, center = TRUE, scale = TRUE, ...)
|
x |
the matrix-like object |
center |
Either a logical, character, or numeric-like value that specifies what to center |
scale |
Either a logical, characeter, or numeric-like value that specifies what to scale |
For instance, you might want to subtract the mean of a subset of columns from each row in the matrix (like the columns that come from control samples)
a scaled version of x
center
and scale
can be a logical, character, or numeric-like vector.
The flexibility enables the following scenarios:
The user can set it to TRUE
to center all values on the mean of their
row. (FALSE
does no centering)
A (named) vector of values that is a superset of rownames(x). These will be the values that are subtracted from each row.
A logical vector as long as ncol(x). Each value will be centered to the mean of the values of the columns specified as TRUE.
An integer vector, the is the analog of 3 but specifies the columns to use for centering.
1 2 3 4 5 6 7 8 9 10 11 | # see tests/testthat/test-scale_rows.R for more examples
m <- matrix(rnorm(50, mean = 1, sd = 2), nrow = 5,
dimnames = list(LETTERS[1:5], letters[1:10]))
s0 <- scale_rows(m, center = TRUE, scale = FALSE)
all.equal(s0, t(scale(t(m), center = TRUE, scale = FALSE)))
# mean center rows to a specific group of control samples (columns)
ctrl <- sample(colnames(m), 3)
s.ctrl <- scale_rows(m, center = ctrl, scale = FALSE)
ctrl.means <- Matrix::rowMeans(m[, ctrl])
all.equal(s.ctrl, t(scale(t(m), center = ctrl.means, scale = FALSE)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.