2020-03-18 10:30:37 +01:00
|
|
|
#' @title Find indices and values of nonzero elements
|
|
|
|
|
#' @description Emulates behavior of `find`
|
2020-03-18 15:02:38 +01:00
|
|
|
#' @param x object or logic operation on an object
|
2021-03-31 10:27:45 +02:00
|
|
|
#' @param sort sort output?
|
2021-11-10 14:02:35 +01:00
|
|
|
find <- function(x, sort = TRUE) {
|
|
|
|
|
if (is.logical(x)) {
|
|
|
|
|
out <- which(x)
|
|
|
|
|
} else {
|
|
|
|
|
out <- which(x > 0)
|
|
|
|
|
}
|
|
|
|
|
if (sort) {
|
|
|
|
|
out <- sort(out)
|
|
|
|
|
}
|
|
|
|
|
return(out)
|
|
|
|
|
}
|