R Standard Deviation
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- 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.9784574The 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.