Course Content

R Introduction: Part I

## R Introduction: Part I

# What is a Factor?

**Factor variables** are a fundamental concept in statistics and data analysis, often referred to as **categorical variables**. These variables differ from numerical variables in that they have a **limited** and **fixed** set of possible values. Examples of factor variables include blood type, currency, and nationality.

Conversely, variables such as monthly income, height, and price are typically not considered categorical due to their **unlimited range of potential values**. However, even these can be converted into categorical variables, a process we will explore in later chapters.

Before creating a factor variable, let's first create a **vector** of currencies:

In fact, a factor is a type of **vector**. To indicate to R that we are working with factor values, we use the `factor()`

function and pass the relevant vector of values as an argument:

Upon execution, not only is the vector of values output, but we also see a line titled `Levels:`

, which indicates all the **distinct** (unique) values the factor can take.

Task

Imagine we conducted a survey on blood groups and received 26 responses, which are now stored in the `blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Task

Imagine we conducted a survey on blood groups and received 26 responses, which are now stored in the `blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Everything was clear?

# What is a Factor?

**Factor variables** are a fundamental concept in statistics and data analysis, often referred to as **categorical variables**. These variables differ from numerical variables in that they have a **limited** and **fixed** set of possible values. Examples of factor variables include blood type, currency, and nationality.

Conversely, variables such as monthly income, height, and price are typically not considered categorical due to their **unlimited range of potential values**. However, even these can be converted into categorical variables, a process we will explore in later chapters.

Before creating a factor variable, let's first create a **vector** of currencies:

In fact, a factor is a type of **vector**. To indicate to R that we are working with factor values, we use the `factor()`

function and pass the relevant vector of values as an argument:

Upon execution, not only is the vector of values output, but we also see a line titled `Levels:`

, which indicates all the **distinct** (unique) values the factor can take.

Task

Imagine we conducted a survey on blood groups and received 26 responses, which are now stored in the `blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Task

`blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Everything was clear?

# What is a Factor?

**Factor variables** are a fundamental concept in statistics and data analysis, often referred to as **categorical variables**. These variables differ from numerical variables in that they have a **limited** and **fixed** set of possible values. Examples of factor variables include blood type, currency, and nationality.

Conversely, variables such as monthly income, height, and price are typically not considered categorical due to their **unlimited range of potential values**. However, even these can be converted into categorical variables, a process we will explore in later chapters.

Before creating a factor variable, let's first create a **vector** of currencies:

In fact, a factor is a type of **vector**. To indicate to R that we are working with factor values, we use the `factor()`

function and pass the relevant vector of values as an argument:

Upon execution, not only is the vector of values output, but we also see a line titled `Levels:`

, which indicates all the **distinct** (unique) values the factor can take.

Task

`blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Task

`blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.

Everything was clear?

**Factor variables** are a fundamental concept in statistics and data analysis, often referred to as **categorical variables**. These variables differ from numerical variables in that they have a **limited** and **fixed** set of possible values. Examples of factor variables include blood type, currency, and nationality.

**unlimited range of potential values**. However, even these can be converted into categorical variables, a process we will explore in later chapters.

Before creating a factor variable, let's first create a **vector** of currencies:

**vector**. To indicate to R that we are working with factor values, we use the `factor()`

function and pass the relevant vector of values as an argument:

`Levels:`

, which indicates all the **distinct** (unique) values the factor can take.

Task

`blood`

vector. Here's what you need to do:

- Display the values of the original vector
`blood`

. - Convert
`blood`

into a factor and assign it to the variable`blood_gr`

. - Display the values of
`blood_gr`

.