splitScale {neuroim} | R Documentation |
Generic function to center/scale row-subsets of a matrix or matrix-like object
Description
Generic function to center/scale row-subsets of a matrix or matrix-like object
Usage
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)
Arguments
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) |
Value
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
Examples
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)))
[Package neuroim version 0.0.6 Index]