mtcars-easystats

datawrangling
tidyverse
eda
en
mtcars
Published

September 7, 2024

1 Exercise

Provide an overview of descriptive statistics on the mtcars dataset using the R package easystats.











2 Solution

Starting R packages:

library(easystats) 
library(tidyverse)  # comfort

Providing the dataset mtcars:

data(mtcars)

Here are some descriptive statistics for the metric variables of the dataset:

describe_distribution(mtcars) 
Variable Mean SD IQR Range Skewness Kurtosis n n_Missing
mpg 20.09 6.03 7.53 (10.40, 33.90) 0.67 -0.02 32 0
cyl 6.19 1.79 4.00 (4.00, 8.00) -0.19 -1.76 32 0
disp 230.72 123.94 221.53 (71.10, 472.00) 0.42 -1.07 32 0
hp 146.69 68.56 84.50 (52.00, 335.00) 0.80 0.28 32 0
drat 3.60 0.53 0.84 (2.76, 4.93) 0.29 -0.45 32 0
wt 3.22 0.98 1.19 (1.51, 5.42) 0.47 0.42 32 0
qsec 17.85 1.79 2.02 (14.50, 22.90) 0.41 0.86 32 0
vs 0.44 0.50 1.00 (0.00, 1.00) 0.26 -2.06 32 0
am 0.41 0.50 1.00 (0.00, 1.00) 0.40 -1.97 32 0
gear 3.69 0.74 1.00 (3.00, 5.00) 0.58 -0.90 32 0
carb 2.81 1.62 2.00 (1.00, 8.00) 1.16 2.02 32 0

What about statistics for the non-metric (nominal) variables (columns)? Let’s restrict the analysis to the columns vs, am, and gear.

data_tabulate(mtcars, select = c("vs", "am", "gear"))
Frequency Table
Variable Value N Raw % Valid % Cumulative %
vs 0 18 56.25 56.25 56.25
1 14 43.75 43.75 100.00
(NA) 0 0.00 (NA) (NA)
am 0 19 59.38 59.38 59.38
1 13 40.62 40.62 100.00
(NA) 0 0.00 (NA) (NA)
gear 3 15 46.88 46.88 46.88
4 12 37.50 37.50 84.38
5 5 15.62 15.62 100.00
(NA) 0 0.00 (NA) (NA)