-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Function:
#' Cumulative Median
#'
#' @family Vector Function
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details
#' A function to return the cumulative median of a vector.
#'
#' @description
#' A function to return the cumulative median of a vector.
#'
#' @parm .x A numeric vector
#'
#' @examples
#' x <- mtcars$mpg
#'
#' cmedian(x)
#'
#' @return
#' A numeric vector
#'
#' @export
#'
cmedian <- function(.x){
sapply(seq_along(.x), function(k, z) stats::median(z[1:k]), z = .x)
}Example:
> cmedian(x)
[1] 21.00 21.00 21.00 21.20 21.00 21.00 21.00 21.00 21.00 21.00 21.00 20.10 19.20
[14] 18.95 18.70 18.40 18.10 18.40 18.70 18.95 19.20 18.95 18.70 18.40 18.70 18.95
[27] 19.20 19.20 19.20 19.20 19.20 19.20Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Projects
Status
Done