# Standard Error in R

Standard error is a statistical measure of the spread of the sample data. It measures how a set of data is spread around the sample mean. While calculating SE involves lots of calculations, R comes with a built-in function to calculate it. This guide will show the calculation of standard error in R.

There are two ways to calculate standard error in R:

## Indirectly using the sd() function

Mathematically, standard error can be calculated by dividing the standard deviation of the input vector by the square root of the length of the input vector::

``Standard Error = sd/√ n``

Here, n denotes the length of the data. sd denotes the standard deviation. To learn how to compute standard Deviation in R, click here.

#### Syntax to compute standard error in R

To compute standard error in R, use the following syntax.

``sd(x)/sqrt(length((x)))``

#### Arguments

1. sd = built-in function to compute standard deviation
2. sqrt = built-in function to find the square root
3. length = built-in function to find the length of the data
4. x = input vector

#### Example

Calculate standard error from a vector with six elements.

``````#creating a vector
height <- c(171,169,178,181,186,177)
#calculating Standard Error
sd(height)/sqrt(length(height))``````

#### Output

``[1] 2.569047``

## Directly using the std.error() function

std.error() comes from the plotrix package. To install and load the package, run the following code:

``````install.packages('plotrix')
library('plotrix')``````

#### Syntax

``std.error(x)``

#### Arguments

• x = input vector

#### Example

Calculate standard error from a vector using std.error() function.

``````#creating a vector
height <- c(171,169,178,181,186,177)
#calculating standard Error
std.error(height)``````

#### Output

``[1] 2.569047``