File: which.first.R

package info (click to toggle)
r-cran-bbmisc 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,256 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#' @title Find the index of first/last \code{TRUE} value in a logical vector
#'
#' @description
#' Returns the index of the first or last TRUE value in a logical vector.
#'
#' @param x [\code{logical}]\cr
#'   Logical vector.
#' @param use.names [\code{logical(1)}]\cr
#'   If \code{TRUE} and \code{x} is named, the result is also
#'   named.
#' @return [\code{integer(1)} | \code{integer(0)}].
#'   Returns the index of the first/last \code{TRUE} value in \code{x} or
#'   an empty integer vector if none is found.
#' @export
#' @examples
#'  which.first(c(FALSE, TRUE))
#'  which.last(c(FALSE, FALSE))
which.first = function(x, use.names = TRUE) {
  wf(x, use.names)
}

#' @rdname which.first
#' @export
which.last = function(x, use.names = TRUE) {
  wl(x, use.names)
}