Description Usage Arguments Value Examples
Generic function to center/scale row-subsets of a matrix or matrix-like object
1 2 3 4 5 6 7 8 | splitScale(x, f, center, scale)
## S4 method for signature 'matrix,factor,logical,logical'
splitScale(x, f, center = TRUE,
scale = TRUE)
## S4 method for signature 'matrix,factor,missing,missing'
splitScale(x, f)
|
x |
a numeric matrix or matrix-like object |
f |
the splitting object, typically a |
center |
should values within each submatrix be centered? (mean removed from each column of submatrix) |
scale |
should values be scaled? (divide vector by standard deviation from each column of submatrix) |
a new matrix or matrix-like object where the original rows have been grouped by f
and then centered and/or scaled for each grouping
1 2 3 4 5 6 7 8 9 10 11 | M <- matrix(rnorm(1000), 10, 100)
fac <- factor(rep(1:2, each=5))
Ms <- splitScale(M, fac)
## correctly centered
all(abs(apply(Ms[fac == 1,], 2, mean)) < .000001)
all(abs(apply(Ms[fac == 2,], 2, mean)) < .000001)
# correctly scaled
all.equal(apply(Ms[fac == 1,], 2, sd), rep(1, ncol(Ms)))
all.equal(apply(Ms[fac == 2,], 2, sd), rep(1, ncol(Ms)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.