In this article, you’ll learn Statistical functions used in R. We will also be each one of them with an example and various ways to use them for better understanding.

R standard installation contains wide range of statistical functions. In this article, we will briefly look at the most important function.

## Arithmetic Meanmean()

Generic function for the (trimmed) arithmetic mean.

## Usage

``````> mean(x, …)
> mean(x, trim = 0, na.rm = FALSE, …)``````

### Example

``````# Create a vector with random values with mean of 50 and sd of 5
> x <- round(rnorm(10, mean = 50, sd = 5))
> x
 52 47 54 51 49 49 60 54 56 50

> mean(x)
 52.2

> mean(x, trim=49)
 51.5``````

## Median Value

Compute the sample median.

### Usage

``median(x, na.rm = FALSE, …)``

### Let’s see it with an example.

``````> median(1:10)
> median(c(2,5,1,3,5,23,34,12,67))
 5``````

## Variance

The variance is a numerical measure of how the data values are dispersed around the mean. In particular, the sample variance is defined as:

### Estimation Of A VAR(P)

Estimation of a VAR by utilizing OLS per equation.

### Usage

``````VAR(y, p = 1, type = c("const", "trend", "both", "none"),
season = NULL, exogen = NULL, lag.max = NULL,
ic = c("AIC", "HQ", "SC", "FPE"))
print(x, digits = max(3, getOption("digits") - 3), ...)``````

### Arguments

Let’s take a built-in dataset `cars` and find the var of speed in cars.

``````# Load the cars dataset
> dt <- cars
> speed <- dt\$speed
> speed
  4  4  7  7  8  9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15
 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25

> var(speed)
 27.95918``````

## Standard Deviation

This function computes the standard deviation of the values in `x`. If `na.rm` is `TRUE` then missing values are removed before computation proceeds.

##### Usage
``sd(x, na.rm = FALSE)``
##### Arguments

Let’s see it with an example using `rnorm()` function.

``````> x = rnorm(10, 10, 20)
> x
  36.1663953  32.9141902  18.7596222 -20.5158583 -15.9542984   0.8033739
  -3.1769068   6.7160742   3.7626753   8.7092254

> sd(x)
 18.55818``````

## Conclusion

Hence, we the various function which are used for statistical programming in R, along with how to use them with each example each.

This brings the end of this Blog. We really appreciate your time.

Hope you liked it. 