R max min Function


max() function computes the maximun value of a vector. min() function computes the minimum value of a vector.

max(x,na.rm=FALSE)
min(x,na.rm=FALSE)

• x: number vector
• na.rm: whether NA should be removed, if not, NA will be returned
...

> x <- c(1,2.3,2,3,4,8,12,43,-4,-1)
> max(x)
[1] 43

> min(x)
[1] -4

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
> max(y)
[1] NA
> min(y)
[1] NA

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

Compare more than 1 vectors:
> x2 <- c(-100,-43,0,3,1,-3)
> min(x,x2)
[1] -100