To caclulate standard error of the mean in R, you can use std.error() function from plotrix package or you can create function to create standard error of the mean.
The following methods show how you can do it with syntax.
Method 1: Use std.error() Function
library(plotrix)
std.error(data)
Method 2: Create Function
function(data) sd(data)/sqrt(length(data))
The following examples show how to calculate standard error of the mean in R.
Use std.error() to Calculate Standard Error of Mean
Let’s see how we can use std.error() function to calculate standard error of mean:
# Import library
library(plotrix)
# Create dataframe
df <- data.frame(Machine_name=c("A","B","C","D","E","F","G","H"),
Pressure1=c(78.2, 28, 71.7, 80.21, 72.7, 30, 84.21, 76.2),
Temperature1=c(31, 33, 36, 37, 36, 33, 37, 31),
Status=c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE))
# Calculate Standard Error of the Mean
m <- std.error(df$Pressure1)
# Display Standard Error of the Mean
print(m)
Output:
[1] 8.015657
Here the output shows standard error of mean for Pressure1 column of dataframe.
Create Function to Calculate Standard Error of Mean
Let’s see how we can create function to calculate standard error of mean in R:
# Create function
std_error <- function(x) sd(x)/sqrt(length(x))
# Create dataframe
df <- data.frame(Machine_name=c("A","B","C","D","E","F","G","H"),
Pressure1=c(78.2, 28, 71.7, 80.21, 72.7, 30, 84.21, 76.2),
Temperature1=c(31, 33, 36, 37, 36, 33, 37, 31),
Status=c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE))
# Calculate standard error mean
m <- std_error(df$Temperature1)
# Display mean
print(m)
Output:
[1] 0.9013878
Here the output shows standard error of mean for Temperature1 column of dataframe.