R Under development (unstable) (2026-01-18 r89306 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library( "miscTools" ) > > > ## matrix > m <- matrix( 1:24, nrow = 6, ncol = 4 ) > > cm1 <- colMedians( m ) > print( cm1 ) [1] 3.5 9.5 15.5 21.5 > > rm1 <- rowMedians( m ) > print( rm1 ) [1] 10 11 12 13 14 15 > > all.equal( cm1, rowMedians( t( m ) ) ) [1] TRUE > all.equal( rm1, colMedians( t( m ) ) ) [1] TRUE > > > ## data.frame > data( "Electricity", package = "Ecdat" ) > Electricity <- Electricity[ 1:20, ] > > cm2 <- colMedians( Electricity ) > print( cm2 ) cost q pl sl pk sk pf 3.09655 422.50000 7794.10000 0.21090 69.26100 0.24415 25.95070 sf 0.59860 > > rm2 <- rowMedians( Electricity ) > print( rm2 ) 1 2 3 4 5 6 7 8 4.20985 12.05485 25.04895 14.64980 20.72935 18.42610 16.34295 7.24435 9 10 11 12 13 14 15 16 11.32520 8.27460 14.17730 13.01815 22.80935 17.95680 14.06405 15.67750 17 18 19 20 15.49855 12.44370 15.61920 21.87700 > > all.equal( cm2, rowMedians( t( Electricity ) ) ) [1] TRUE > all.equal( rm2, colMedians( t( Electricity ) ) ) [1] TRUE > > # array (3 dimensions) > a3 <- array( 1:24, dim = c(4,3,2), + dimnames = list( c("a","b","c","d"), c("A","B","C"), c("x","y") ) ) > colMedians( a3 ) x y A 2.5 14.5 B 6.5 18.5 C 10.5 22.5 > all.equal( median( a3[ , "B", "y" ] ), colMedians( a3 )[ "B", "y" ] ) [1] TRUE > > # array (4 dimensions) > 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 > all.equal( median( a4[ , "B", "x", "Z" ] ), colMedians( a4 )[ "B", "x", "Z" ] ) [1] TRUE > > proc.time() user system elapsed 0.15 0.04 0.18