indexByRow: Translates matrix indices by rows into indices by columns

Description Usage Arguments Value Author(s) Examples

Description

Translates matrix indices by rows into indices by columns.

Usage

1
2
 ## S3 method for class 'matrix'
indexByRow(x, idxs=NULL, ...)

Arguments

x

A matrix.

idxs

A vector of indices. If NULL, all indices are returned.

...

Not use.

Value

Returns an integer vector of indices.

Author(s)

Henrik Bengtsson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 x <- matrix(NA, nrow=5, ncol=4)
 y <- t(x)
 idxs <- seq(along=x)

 # Assign by columns
 x[idxs] <- idxs
 print(x)

 # Assign by rows
 y[indexByRow(y, idxs)] <- idxs
 print(y)

 stopifnot(x == t(y))

matrixStats documentation built on May 2, 2019, 4:52 p.m.