colMedians.RdCompute the sample medians of the columns (non-rows) of a data.frame or array.
colMedians( x, na.rm = FALSE )A vector or array of the medians of each column (non-row) of x
with dimension dim( x )[-1].
data( "Electricity", package = "Ecdat" )
colMedians( Electricity )
#> cost q pl sl pk sk pf sf
#> 25.5454 5645.5000 7890.1850 0.1231 74.1200 0.2186 30.6579 0.6450
a4 <- array( 1:120, dim = c(5,4,3,2),
dimnames = list( c("a","b","c","d","e"), c("A","B","C","D"),
c("x","y","z"), c("Y","Z") ) )
colMedians( a4 )
#> , , Y
#>
#> x y z
#> A 3 23 43
#> B 8 28 48
#> C 13 33 53
#> D 18 38 58
#>
#> , , Z
#>
#> x y z
#> A 63 83 103
#> B 68 88 108
#> C 73 93 113
#> D 78 98 118
#>
median( a4[ , "B", "x", "Z" ] ) # equal to
#> [1] 68
colMedians( a4 )[ "B", "x", "Z" ]
#> [1] 68