R/zp_judge.R

Defines functions judge_123 judge_321

Documented in judge_123 judge_321

#' Whether the Data Is Arranged from Small to Large
#'
#' @param x numeric vector
#'
#' @return logical
#' @export
#'
#' @examples
#' judge_123(c(1,2,3,4,5))
#' judge_123(c(1,3,2))
judge_123 <- function(x){
    x=x[!is.na(x)]
    if (length(x)==1) return(TRUE)
    for (i in 1:(length(x)-1)) {
        if (x[i] > x[i+1]) return(FALSE)
    }
    return(TRUE)
}
#' Whether the Data Is Arranged from Large to Small
#'
#' @param x numeric vector
#'
#' @return logical
#' @export
#'
#' @examples
#' judge_321(c(5,4,3,2,1))
#' judge_321(c(3,1,2))
judge_321 <- function(x){
    x=x[!is.na(x)]
    if (length(x)==1) return(TRUE)
    for (i in 1:(length(x)-1)) {
        if (x[i] < x[i+1]) return(FALSE)
    }
    return(TRUE)
}

Try the cutoff package in your browser

Any scripts or data that you put into this service are public.

cutoff documentation built on Jan. 11, 2020, 9:39 a.m.