The standard deviation is the square root of the variance. Thus the way we calculate standard deviation is very similar to the way we calculate variance. In fact, to calculate standard deviation, we first need to calculate the variance, and then take its square root.
When calculating the mean across a set of variables (or columns) in R, we have colMeans at our disposal. What do we do if we want to want to calculate say the standard deviation?
There are a couple of packages offering such a function, but there is no need, because we have apply.Let’s start with creating some data, a matrix with 3 columns full of random numbers.M.
The following example code may prove useful. # Create a 5 column dataframe that contains some NAscol1.