From 4d9ed9210fdba02478d6af3316851a779ac982cb Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 31 Mar 2021 10:27:45 +0200 Subject: [PATCH] Added sorting of output on find() --- R/find.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/find.R b/R/find.R index 788b6ec..5e5efff 100644 --- a/R/find.R +++ b/R/find.R @@ -1,10 +1,15 @@ #' @title Find indices and values of nonzero elements #' @description Emulates behavior of `find` #' @param x object or logic operation on an object -find <- function(x) { +#' @param sort sort output? +find <- function(x, sort=TRUE) { if (is.logical(x)) { - return(which(x)) + out <- which(x) } else { - return(which(x > 0)) + out <- which(x > 0) } + if (sort) { + out <- sort(out) + } + return(out) } \ No newline at end of file