Learn R Programming

useful (version 1.2.6)

indexToPosition: indexToPosition

Description

Given a long matrix index convert to row and column positions

Usage

indexToPosition(x, nrow = 1)

Value

A Matrix with row and column columns and a row for each value of x

Arguments

x

Position of indices

nrow

The number of rows in the matrix

Author

Jared P. Lander

Details

Using which on a matrix returns a number that iterates down rows then across columns. This function returns the (row, column) position of that index.

Examples

Run this code
indexToPosition(3, 2)
indexToPosition(c(1, 4, 5, 7, 9), 3)
indexToPosition(1:16, 4)
indexToPosition(c(1, 3, 5, 6, 8, 10, 11, 13, 15), 5)

Run the code above in your browser using DataLab