x <- matrix( rnorm(1000 * 1000), ncol = 1000 )
system.time( a1 <- colrange(x) )
system.time( a2 <- apply(x, 2, function(x) diff( range(x)) ) )
all.equal(a1, a2)
system.time( a1 <- rowrange(x) )
system.time( a2 <- apply(x, 1, function(x) diff( range(x)) ) )
all.equal(a1, a2)
Run the code above in your browser using DataLab