Computes the median value for each column in a matrix or a data frame.

ct_medianCol(x)

Arguments

x

A matrix or a data frame.

Value

An n x 1 matrix with the median value for each column in x. The rownames are the colnames of x. For each column, the function first sorts the values in ascending order. Then, if the length of the column (=n) is divisible by 2, then the median will be computed as the mean(C_n/2, C_n/2+1). Otherwise, if the length of the column (=n) is NOT div by 2, then the median will be computed as C_n/2+1=C_as.integer(n/2+1).

Examples

dataTest1=cbind(c(10,50,12,43), c(100, 101, 102, 103), c(1, 1, 5,4))
#note that length(dataTest1[,1]) is 4 and thus divisible by 2
colnames(dataTest1)=c("Variable 1", "Variable 2", "Variable 3")
ct_medianCol(dataTest1)
#>            Median
#> Variable 1   27.5
#> Variable 2  101.5
#> Variable 3    2.5

dataTest2=cbind(c(10,50,12,43,10), c(100, 101, 102, 103, 103), c(1, 1, 5,4, 7))
#note that length(dataTest2[,1]) is 5 and thus NOT divisible by 2
colnames(dataTest2)=c("Variable 1", "Variable 2", "Variable 3")
ct_medianCol(dataTest2)
#>            Median
#> Variable 1     12
#> Variable 2    102
#> Variable 3      4