Lesson 3

Welcome back! You've already learned about **strings** and **numerics** in R. These foundational concepts are crucial for working with data. Now, let's take the next step and explore how to compare values using comparison operators in R.

In this lesson, you will discover how to:

- Use various comparison operators in R to compare numeric values.
- Evaluate conditions using these operators.

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

R`1# Assigning numeric variables 2a <- 7 3b <- 42 4 5# Using comparison operators 6is_equal <- a == b # FALSE 7is_not_equal <- a != b # TRUE 8is_greater <- a > b # FALSE 9is_less <- a < b # TRUE 10is_greater_equal <- a >= b # FALSE 11is_less_equal <- a <= b # TRUE 12 13# Print the results 14print(is_equal) 15print(is_not_equal) 16print(is_greater) 17print(is_less) 18print(is_greater_equal) 19print(is_less_equal)`

By the end of this unit, you'll be able to write conditions and make decisions in your R programs effectively.

Comparison operators are essential for making decisions in programming, especially when handling data. They allow you to compare values and return logical results (`TRUE`

or `FALSE`

). This is crucial for data filtering and manipulation, enabling you to subset data, filter out unwanted observations, and analyze specific conditions within your data.

For example, you might want to filter a dataset to include only rows where a certain condition is met, such as values above a threshold or specific categorical matches. Understanding comparison operators will empower you to perform such data handling tasks efficiently and accurately.

Exciting, right? Now, let's dive into the practice section and explore comparison operators in R together!