Working with univariate descriptive statistics in R
Univariate descriptive statistics describes a single variable for unit analysis, which is also the simplest form of quantitative analysis. In this recipe, we introduce some basic functions used to describe a single variable.
Getting ready
We need to apply descriptive statistics to a sample data. Here, we use the built-in mtcars
data as our example.
How to do it...
Perform the following steps:
- First, load the
mtcars
data into a data frame with a variable namedmtcars
:> data(mtcars)
- To obtain the vector range, the
range
function will return the lower and upper bound of the vector:> range(mtcars$mpg) [1] 10.4 33.9
- Compute the length of the variable:
> length(mtcars$mpg) [1] 32
- Obtain the mean of mpg: ...
Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.