Introduction to Descriptive Statistics and R

Greetings, data enthusiast! Today, we're diving into descriptive statistics using R. We'll explore measures of centrality — the mean, median, and mode — using R's built-in functionalities.

Understanding Central Tendency

Central tendency finds a 'typical' value in a dataset. Our three components — the mean (average), median (mid-point), and mode (most frequently occurring) — each offer a unique perspective on centrality. The mean indicates average performance when decoding students' scores, while the median represents the performance of the middle student, and the mode illuminates the most common score.

Visualizing Central Tendency

This plot depicts the mean of a given dataset or its centered location, also considered the 'average'. Imagine a seesaw balanced at its center - the mean of a dataset is where it finds balance. As a crucial statistical concept, it visually expresses where most of our data is centered or skewed.

Setting up the Dataset

Our dataset is a list of individuals' ages: c(23, 22, 22, 23, 24, 24, 23, 22, 21, 24, 23). Remember, understanding your data upfront is vital for meaningful analysis.

Computing Mean using R

Calculating the mean involves adding all the numbers together and then dividing by the count. Here's how to compute it using R:

data <- c(23, 22, 22, 23, 24, 24, 23, 22, 21, 24, 23)
mean_val <- mean(data)  # calculates the mean
cat("Mean: ", round(mean_val, 2))  # Mean:  22.82
Computing Median using R

R calculates the median, the 'middle' value in an ordered dataset, using the built-in function median(). Here is how to do it:

data <- c(23, 22, 22, 23, 24, 24, 23, 22, 21, 24, 23)
median_val <- median(data)  # calculates the median
cat("Median: ", median_val)  # Median:  23
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal