R/capply.R

Defines functions capply

Documented in capply

#' Conditional Apply
#' 
#' A wrapper for \code{ifelse(test(x), fun(x, ...), x)}
#' 
#' @param test a test that returns a logical 
#' @param fun to apply
#' @param x data to apply fun to.
#' @param ... other arguments to fun
#' 
capply <- function(test, x, fun, ...){
    ifelse(Map(test, x), fun(x, ...), x)
}

Try the dostats package in your browser

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

dostats documentation built on May 11, 2022, 1:08 a.m.