The interquartile range can be calculated using the IQR()
function:
IQR(
pss$stfdem,
na.rm = TRUE
)
A more customizable alternative is to combine the diff()
and quantile()
functions. In the quantile()
function, you specify the variable (\(1^{st}\) argument), the desired quantiles (\(2^{nd}\) argument), and finally exclude NA's
. The function returns two values, and the diff()
function calculates and outputs the difference between these two values.
diff(
quantile(
pss$stfdem,
probs = c(
0.25,
0.75
),
na.rm = TRUE
)
)
We obtain the standard deviation and variance using the following two functions:
sd(
pss$stfdem,
na.rm = TRUE
)
var(
pss$stfdem,
na.rm = TRUE
)
Now, let’s take a step further into data processing and enter the tidyverse
!