Learn R Programming

noah (version 0.1.0)

ind2subs: Convert linear index to matrix subscripts

Description

Takes a vector of integers (1D linear indexed) and converts them to matrix subscripts in n-dimensional matrix. Modeled after MATLAB's ind2sub()

Usage

ind2subs(ind, dims)

Arguments

ind

An integer vector with linear indexes

dims

An n-dimensional integer vector. Each element of this vector indicates the size of the corresponding dimension in the n-dimensional matrixc.

Value

A list of n lists of equal length. Each list corresponds to one of the n dimensions of the matrix. Rows indicate subscripts. Suitable for use with mapping functions.