There are a lot of built-in function in R. R matches your input parameters with its function arguments, either by value or by position, then executes the function body. Function arguments can have default values: if you do not specify these arguments, R will take the default value.
- General function
- Maths function
- Statistical function
If you work on time series, you need to stationary the series by taking their lag values. A stationary process allows constant mean, variance and autocorrelation over time. This mainly improves the prediction of a time series. It can be easily done with the function diff(). We can build a random time-series data with a trend and then use the function diff() to stationary the series. The diff() function accepts one argument, a vector, and return suitable lagged and iterated difference.
In many cases, we want to know the length of a vector for computation or to be used in a for loop. The length() function counts the number of rows in vector x. The following codes import the cars dataset and return the number of rows.
R has an array of mathematical functions.
|abs(x)||Takes the absolute value of x|
|log(x,base=y)||Takes the logarithm of x with base y; if base is not specified, returns the natural logarithm|
|exp(x)||Returns the exponential of x|
|sqrt(x)||Returns the square root of x|
|factorial(x)||Returns the factorial of x (x!)|
Mean of x
Median of x
Variance of x
Standard deviation of x
Standard scores (z-scores) of x
The quartiles of x
Summary of x: mean, min, max etc..