Skip to contents

Sort a matrix in a row- or column-wise manner, or check that it is

rowSort sort each row independently
colSort sort each column independently

rowSorted check that each row is independently sorted
colSorted check that each column is independently sorted

Usage

rowSort(mat, by = NULL, ncol = NULL, decreasing = FALSE)

colSort(mat, by = NULL, ncol = NULL, decreasing = FALSE)

rowSorted(mat, decreasing = FALSE)

colSorted(mat, decreasing = FALSE)

Arguments

mat

matrix to sort or to check

by

matrix to sort by. If NULL, sort mat by itself (default)

ncol

number of desired columns for the sorted mat. If NULL, keep original dimensions of mat (default)

decreasing

logical. Should the sort be increasing or decreasing? Not available for partial sorting.

Value

a sorted matrix of ncol columns

Note

If mat and by have different dimensions, results might be incorrect