S has built into it many standard mathematical and statistical functions.
Function Value log(x) the natural logarithm of each element of x logb(x,b) the base b logarithm of each element of x exp(x) the exponential of each element of x, ie. e^x sqrt(x) the square root of each value of x mean(x) the arithmetic average of the vector x median(x) the median value of x var(x) the variance of x; note: the standard deviation of x is sqrt(var(x)) max(x) the largest value in x min(x) the smallest value in x range(x) equivalent to c(min(x),max(x)) sum(x) the sum of the elements in x rank(x) the relative rank of each element found in x sort(x) the values of x sorted into ascending order
There are numerous functions in S, including much more complicated ones such as the `lm()' function, which does linear regression calculations.
You can also create your own functions. For example:
> # create the function > sd <- function(x){sqrt(var(x))} > # print the function > sd function(x) { sqrt(var(x)) } > # use the function > y <- 1:5 > sd(y) [1] 1.581139