# How to Calculate the Standard Error of the Mean in R?

In this article, we will discuss how to calculate the standard error of the mean in the R programming language.

StandardError Of Mean is the standard deviation divided by the square root of the sample size.

Formula:

Standard Error: (Sample Standard Deviation of Sample)/(Square Root of the sample size)

## Method 1: Using the std.error() function of the Plotrix package

In this method to calculate the standard error of the mean, the user first needs to install and import the plotrix package, here the plotrix package is responsible to provide various functionalities to the user, then the user simply needs to call the std.error() function with the data passed as its parameters for which the standard error is to be calculated of the provided data in the R programming language.

Syntax to install and import the plotrix package in the R console:

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

std.error() function is used to calculate the standard error of the mean.

Syntax:

std.error(x,na.rm)

Parameters:

• x: A vector of numerical observations.
• na.rm: Dummy argument to match other functions.

Example: Calculate standard error of mean

## R

 `library``(plotrix) ` ` `  `# Create data ` `gfg <- ``c``(1:100) ` ` `  `# calculate standard error of the mean  ` `std.error``(gfg)`

Output:

` 2.901149`

## Method 2: Using the formula

In the method, the user has to simply use the standard error of the mean formula to calculate the standard error of the mean of the given data which is the sample standard deviation of the data which will be calculated using the sd() function divided by the square root of the length of the data which will be calculating using the sqrt() and the length() function in the R programming language.

Formula:

Standard Error: (Sample Standard Deviation of Sample)/(Square Root of the sample size)

Example: Calculate standard error of mean

## R

 `# Create data ` `gfg <- ``c``(1:100) ` ` `  `# calculate standard error of the mean  ` `std_error<-``sd``(gfg)/``sqrt``(``length``(gfg)) ` `std_error`

Output:

` 2.901149`
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Previous
Next