Added sorting of output on find()

This commit is contained in:
Waldir Leoncio 2021-03-31 10:27:45 +02:00
parent e1642f24e5
commit 4d9ed9210f

View file

@ -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)
}