sortrows: Sort Rows of a Matrix (Matlab Style)

Description Usage Arguments Details Value See Also Examples

View source: R/repmat.R

Description

Sort rows of a matrix according to values in a column.

Usage

1
sortrows(A, k = 1)

Arguments

A

numeric matrix.

k

number of column to sort the matrix accordingly.

Details

sortrows(A, k) sorts the rows of the matrix A such that column k is increasingly sorted.

Value

Returns the sorted matrix.

See Also

sort

Examples

1
2
3
A <- magic(5)
sortrows(A)
sortrows(A, k = 2)

Example output

     [,1] [,2] [,3] [,4] [,5]
[1,]    4    6   13   20   22
[2,]   10   12   19   21    3
[3,]   11   18   25    2    9
[4,]   17   24    1    8   15
[5,]   23    5    7   14   16
     [,1] [,2] [,3] [,4] [,5]
[1,]   23    5    7   14   16
[2,]    4    6   13   20   22
[3,]   10   12   19   21    3
[4,]   11   18   25    2    9
[5,]   17   24    1    8   15

pracma documentation built on Dec. 11, 2021, 9:57 a.m.