Added sorting of output on find()
This commit is contained in:
parent
e1642f24e5
commit
4d9ed9210f
1 changed files with 8 additions and 3 deletions
11
R/find.R
11
R/find.R
|
|
@ -1,10 +1,15 @@
|
||||||
#' @title Find indices and values of nonzero elements
|
#' @title Find indices and values of nonzero elements
|
||||||
#' @description Emulates behavior of `find`
|
#' @description Emulates behavior of `find`
|
||||||
#' @param x object or logic operation on an object
|
#' @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)) {
|
if (is.logical(x)) {
|
||||||
return(which(x))
|
out <- which(x)
|
||||||
} else {
|
} else {
|
||||||
return(which(x > 0))
|
out <- which(x > 0)
|
||||||
}
|
}
|
||||||
|
if (sort) {
|
||||||
|
out <- sort(out)
|
||||||
|
}
|
||||||
|
return(out)
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue