Calculate Standard Error in R

The standard error (SE) of a statistic is the standard deviation of its sampling distribution or an estimate of that standard deviation. The standard error is calculated by dividing the standard deviation by the square root of the number of sample data.

The formula for calculating Standard Deviation in the Mathematics world is 

Se = \Sigma / Sqrt(N)
Standard Error Formula
standard error= standard deviation/squareroot(n)
  • SE = standard error of the sample
  • σ = sample standard deviation
  • n = number of samples

In this tutorial, we will look at how to Calculate Standard Error in R with examples.

How to Calculate Standard Error in R?

We can calculate Standard Error in three ways in the R language, as shown below.

Using sd() method

The sd() method takes a numeric vector as input and computes the standard deviation.

> std <- function(x) sd(x)/sqrt(length(x))
> std(c(1,2,3,4))
[1] 0.6454972

Using the standard error formula

We can use the standard error formula and calculate the standard error manually as shown below.

Syntax: sqrt(sum((a-mean(a))^2/(length(a)-1)))/sqrt(length(a))


  • data is the input data
  • sqrt function is to find the square root
  • sum is used to find the sum of elements in the data
  • mean is the function used to find the mean of the data
  • length is the function used to return the length of the data

# consider a vector with 10 elements
a <- c(1,2,3,4)
# calculate standard error
print(sqrt(sum((a - mean(a)) ^ 2/(length(a) - 1)))

[1] 0.6454972

Using std.error() method from plotrix

We can import the plotrix library and use the std.error() method to calculate the standard error.

# import plotrix package
# vector data
a <- c(1,2,3,4)
# calculate standard error using builtin function

[1] 0.6454972
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like