1. Descriptive Statistics: Practical 1
Measures of Spread
Measures of Spread
The most frequently used measure for the spread is the standard deviation (or it's square: the variance). In R the commands to calculate these statistics are sd() and var(). You can use these functions the same way as the functions for central tendency.
Use the gapminder data:
What is the standard deviation of the variable 'lifeExp' for 2007?
What is the standard deviation of the variable 'lifeExp' for 2007?
The standard deviation of the variable 'lifeExp' for 2007#=# #12#
First, create a subset with only data of 2007:
Alternatively, you can do this also in one line by selecting all the rows in which the year is 2007 and selecting the column 'lifeExp'. Apply
First, create a subset with only data of 2007:
G2007 <- G[G$year == 2007,]Then apply the function for standard deviation on the variable lifeExp.
sd(G2007$lifeExp)
Alternatively, you can do this also in one line by selecting all the rows in which the year is 2007 and selecting the column 'lifeExp'. Apply
sd() to this selection. sd(G[G$year == 2007, 'lifeExp'])
Unlock full access