R range Function


range() function get a vector of the minimum and maximum values.

range(..., na.rm = FALSE, finite = FALSE)

...: numeric vector
na.rm: whether NA should be removed, if not, NA will be returned
finite: whether non-finite elements should be omitted

>x <- c(1,2.3,2,3,4,8,12,43,-4,-1)
>r <- range(x)
>r
[1] -4 43
>diff(r)
[1] 47

Missing value affect the results:
>y<- c(x,NA)
>y
[1]  1.0  2.3  2.0  3.0  4.0  8.0 12.0 43.0 -4.0 -1.0   NA
>range(y)
[1] NA NA

After define na.rm=TRUE, result is meaningful:
>range(y,na.rm=TRUE)
[1] -4 43

> range(y,finite=TRUE)
[1] -4 43