Learn R Programming

matrixStats (version 0.1.5)

indexByRow: Translates matrix indices by rows into indices by columns

Description

Translates matrix indices by rows into indices by columns.

Usage

indexByRow(x, idxs=NULL, ...)

Arguments

x
idxs
A vector of indices. If NULL, all indices are returned.
...
Not use.

Value

Examples

Run this code
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))

Run the code above in your browser using DataLab