Friday, September 4, 2026
Home FEATURED Calculate Mean and Standard deviation in R

Calculate Mean and Standard deviation in R

In R, you can use the mean() function to calculate the mean of a numerical vector, and the sd() function to calculate the standard deviation of a numerical vector. Here is an example:

# Create a numerical vector
x <- c(1, 2, 3, 4, 5)

# Calculate the mean
mean(x)

# Calculate the standard deviation
sd(x)

You can also use the summary() function to get the mean and standard deviation together with other summary statistics of a numerical vector.
There is also a package called psych which has more advanced functionality for calculating descriptive statistics, like describe() function which gives a more detailed summary of the data.

library(psych)
describe(x)

You can install the package by using install.packages("psych") and load the package by using library(psych).

datasagarhttp://www.DataSagar.com
Sagar is multidisciplinary technologist, educator, and entrepreneur based in Nepal. As the founder of Illionso Technologies and Kashi Garden Resort, he operates at the intersection of web architecture, data intelligence, innovation, and digital transformation. From building digital solutions to scaling real-world concepts, his mission is to share knowledge alongside merge emerging as well as disruptive technologies with transformative offline experiences.
RELATED ARTICLES

Most Popular