diff --git a/R/sortrows.R b/R/sortrows.R new file mode 100644 index 0000000..28c4d25 --- /dev/null +++ b/R/sortrows.R @@ -0,0 +1,15 @@ +#' @title Sort rows of matrix or table +#' @description Emulates the behavior of the `sortrows` function on Matlab +#' @param A matrix +#' @param column ordering column +sortrows <- function(A, column = 1) { + if (length(column) == 1) { + new_row_order <- order(A[, column]) + } else if (length(column) == 2) { + new_row_order <- order(A[, column[1]], A[, column[2]]) + } else { + stop("Not yet implemented for 2+ tie-breakers") + } + A_reordered <- A[new_row_order, ] + return(A_reordered) +} \ No newline at end of file diff --git a/man/sortrows.Rd b/man/sortrows.Rd new file mode 100644 index 0000000..b761bec --- /dev/null +++ b/man/sortrows.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sortRows.R +\name{sortrows} +\alias{sortrows} +\title{Sort rows of matrix or table} +\usage{ +sortrows(A, column = 1) +} +\arguments{ +\item{A}{matrix} + +\item{column}{ordering column} +} +\description{ +Emulates the behavior of the `sortrows` function on Matlab +}