Center and/or Scale Row-subsets of a Matrix or Matrix-like Object
Source:R/all_generic.R
, R/common.R
split_scale-methods.Rd
This function centers and/or scales the row-subsets of a numeric matrix or matrix-like object.
Implementation of split_scale for matrix objects.
See split_scale
for the generic definition and complete documentation.
Implementation of split_scale for matrix objects.
See split_scale
for the generic definition and complete documentation.
Implementation of split_scale for DenseNeuroVec objects.
See split_scale
for the generic definition and complete documentation.
Implementation of split_scale for DenseNeuroVec objects.
See split_scale
for the generic definition and complete documentation.
Implementation of split_scale for DenseNeuroVec objects.
See split_scale
for the generic definition and complete documentation.
Usage
split_scale(x, f, center, scale)
# S4 method for class 'matrix,factor,logical,logical'
split_scale(x, f, center = TRUE, scale = TRUE)
# S4 method for class 'matrix,factor,missing,missing'
split_scale(x, f)
# S4 method for class 'DenseNeuroVec,factor,missing,missing'
split_scale(x, f)
# S4 method for class 'DenseNeuroVec,factor,logical,missing'
split_scale(x, f, center)
# S4 method for class 'DenseNeuroVec,factor,logical,logical'
split_scale(x, f, center, scale)
Arguments
- x
A DenseNeuroVec object
- f
Factor for grouping
- center
Logical indicating whether to center
- scale
Logical indicating whether to scale
Value
A new matrix or matrix-like object in which the original rows have been grouped by 'f' and then centered and/or scaled for each grouping.
Matrix of scaled values
Matrix of scaled values
Scaled DenseNeuroVec object
Scaled DenseNeuroVec object
Scaled DenseNeuroVec object
Examples
M <- matrix(rnorm(1000), 10, 100)
fac <- factor(rep(1:2, each=5))
Ms <- split_scale(M, fac)
## Correctly centered
all(abs(apply(Ms[fac == 1,], 2, mean)) < .000001)
#> [1] TRUE
all(abs(apply(Ms[fac == 2,], 2, mean)) < .000001)
#> [1] TRUE
## Correctly scaled
all.equal(apply(Ms[fac == 1,], 2, sd), rep(1, ncol(Ms)))
#> [1] TRUE
all.equal(apply(Ms[fac == 2,], 2, sd), rep(1, ncol(Ms)))
#> [1] TRUE