splitScale-methods: Generic function to center/scale row-subsets of a matrix or...

Description Usage Arguments Value Examples

Description

Generic function to center/scale row-subsets of a matrix or matrix-like object

Usage

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)

Arguments

x

a numeric matrix or matrix-like object

f

the splitting object, typically a factor or set of integer indices. must be equal to number of rows of matrix.

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

 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)))

neuroim documentation built on May 2, 2019, 1:04 p.m.