Rfast (version 1.7.3)

Column and row-wise range of values of a matrix: Column and row-wise range of values of a matrix.

Description

Column and row-wise range of values of a matrix.

Usage

colrange(x, cont = TRUE) rowrange(x, cont = TRUE)

Arguments

x
A numerical matrix with data.
cont
If the data are continuous, leave this TRUE and it will return the range of values for each variable (column). If the data are integers, categorical, or if you want to find out the number of unique numbers in each column set this to FALSE.

Value

A vector with the relevant values.

See Also

colMins, colMaxs, rowMins, rowMaxs, nth, colMedians, colVars, sort_mat

Examples

Run this code
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