Lesson 5

Welcome to the next step in your R programming journey! In the previous lessons, you learned about *strings*, *numerics*, *vectors*, and *comparison operators*. Now, we will take those foundational skills to the next level by diving into **basic statistical functions**. These functions are essential tools for analyzing data, and mastering them will be crucial for working on real-world data analysis projects.

In this section, you will explore various **basic statistical functions** available in `R`

. Specifically, you will learn how to:

- Calculate statistical metrics such as the
`mean`

and`median`

. - Find the
`minimum`

and`maximum`

values of a dataset.

Here's a preview of what we'll be doing:

R`1# Create a numeric vector 2numeric_vec <- c(5, 10, 15, 20, 25) 3 4# Calculate the mean (average) of the numeric vector 5mean_value <- mean(numeric_vec) # 15 6 7# Calculate the median (middle value) of the numeric vector 8median_value <- median(numeric_vec) # 15 9 10# Find the minimum value in the numeric vector 11min_value <- min(numeric_vec) # 5 12 13# Find the maximum value in the numeric vector 14max_value <- max(numeric_vec) # 25`

In R, functions are essential building blocks that help you perform specific tasks. A function usually takes one or more arguments (inputs) and returns a value (output). You've already been using the `print()`

function to display outputs in the console. Functions in R simplify complex operations and make your code more modular and reusable.

For example, the `mean()`

function calculates the average of a numeric vector, while the `max()`

function finds the maximum value. Each function in R is designed to accomplish a specific task, making data manipulation and analysis easier and more efficient.

We'll also be using these functions extensively in future courses, building on your foundational knowledge to tackle more complex data analysis tasks.

Statistical functions are the backbone of data analysis. They provide quick insights into the dataset's central tendency, dispersion, and range, allowing you to make informed decisions. For example, understanding the `mean`

and `median`

of a set of numbers can help you summarize the data, while knowing the `variance`

and `standard deviation`

can give you an idea about the data's spread.

By the end of this Unit, you'll be proficient in using basic statistical functions such as `mean()`

, `median()`

, `sum()`

and many more! These functions will help you draw meaningful insights from your data, making it easier to understand and analyze your datasets!

Excited to start analyzing data? Let's move on to the practice section and get hands-on with these statistical functions in `R`

!