scale_rows | R Documentation |
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.
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 |
... |
pass through arguments |
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)
Note that this method returns different attrs() for scaling and center than base:scale does. Our values are always named.
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.
# 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.