Learn R Programming

useful (version 1.2.4)

indexToPosition: indexToPosition

Description

Given a long matrix index convert to row and column positions

Usage

indexToPosition(x, nrow = 1)

Arguments

x

Position of indices

nrow

The number of rows in the matrix

Value

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

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
# NOT RUN {
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