ourMELONS/R/find.R

16 lines
349 B
R
Raw Normal View History

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?
find <- function(x, sort = TRUE) {
if (is.logical(x)) {
out <- which(x)
} else {
out <- which(x > 0)
}
if (sort) {
out <- sort(out)
}
return(out)
}