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 variance of the variable 'pop' for 1982?
What is the variance of the variable 'pop' for 1982?
The variance of the variable 'pop' for 1982#=# # 1.104573e+16 #
First, create a subset with only data of 1982:
Alternatively, you can do this also in one line by selecting all the rows in which the year is 1982 and selecting the column 'pop'. Apply
First, create a subset with only data of 1982:
G1982 <- G[G$year == 1982,]Then apply the function for variance on the variable pop.
var(G1982$pop)
Alternatively, you can do this also in one line by selecting all the rows in which the year is 1982 and selecting the column 'pop'. Apply
var()
to this selection. var(G[G$year == 1982, 'pop'])
Unlock full access