Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

R Standard Deviation


Share

Standard Deviation

The mean tells you the average value. But two sets of numbers can have the same mean, and still be very different.

Both sets in this example have the mean 5. In the first set, all the values are close to 5. In the second set, they are spread far out.

The standard deviation measures how spread out the values are. Use the sd() function to find it:

Example

a <- c(4, 5, 6)
b <- c(1, 5, 9)

mean(a)
mean(b)

sd(a)
sd(b)

Result:

[1] 5
[1] 5
[1] 1
[1] 4
Try it Yourself »
  • A low standard deviation means that most values are close to the mean.
  • A high standard deviation means that the values are spread out over a wider range.

Standard Deviation of a Data Set

Find the standard deviation of the weight (wt) of the cars in the mtcars data set:

Example

Data_Cars <- mtcars

sd(Data_Cars$wt)

Result:

[1] 0.9784574
Try it Yourself »

The mean weight is 3.21725 (3217 lbs). The standard deviation tells us that most cars weigh about 0.98 (980 lbs) more or less than that.

Tip: If you are new to statistics, read more about standard deviation in our Statistics Tutorial.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.