sd

sd is a function that calculates the standard deviation of a vector of values, or of the values in a data.frame’s column.

Standard deviation can also be manually calculated using the following equation: sqrt(sumln - mean(data ^ 2 / (length(data) - 1))) where data is our vector or data.frame. This page will discuss using the sd function as a replacement to manually calculating the standard deviation, but this is a great tool to cross-check our code to ensure it works.

Examples

How do I get the standard deviation of the values in a vector?

Click to see solution
weights <- c(147, 280, 180, 190, 145)
sd(weights)
[1] 49.114560

How do I get the standard deviation of the values in a vector when some of the values are: NA, NaN?

Click to see solution
weight <- (c(147, NA, 280, 180, 190, 145, NaN), na.rm=T)
sd(weights)
[1] 49.114560