Computes the median value of the values of a vector.

ct_median(x)

Arguments

x

A numeric vector.

Value

A number. First sorts the vector's values in ascending order. Then, if the length of the vector (=n) is divisible by 2, then the median will be computed as the mean(X_n/2, X_n/2+1). Otherwise, if the length of the vector (=n) is NOT div by 2, then the median will be computed as X_n/2+1=X_as.integer(n/2+1).

Examples

ct_median(c(10,50,12,43))
#> [1] 12
#note that length(c(10,50,12,43)) is 4 and thus, divisible by 2

ct_median(c(10,50,12,43, 10))
#> [1] 12
#note that length(c(10,50,12,43, 10)) is 5 and thus, not divisible by 2