Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is a Factor? | Factors
R Introduction: Part I
course content

Conteúdo do Curso

R Introduction: Part I

R Introduction: Part I

1. Basic Syntax and Operations
2. Basic Data Types and Vectors
3. Factors

bookWhat 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:

1234
# Vector of currencies curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') typeof(curr)
copy

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:

12345
curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') # Convert into factor curr_f <- factor(curr) curr_f
copy

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.

Tarefa

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:

  1. Display the values of the original vector blood.
  2. Convert blood into a factor and assign it to the variable blood_gr.
  3. Display the values of blood_gr.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
toggle bottom row

bookWhat 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:

1234
# Vector of currencies curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') typeof(curr)
copy

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:

12345
curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') # Convert into factor curr_f <- factor(curr) curr_f
copy

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.

Tarefa

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:

  1. Display the values of the original vector blood.
  2. Convert blood into a factor and assign it to the variable blood_gr.
  3. Display the values of blood_gr.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
toggle bottom row

bookWhat 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:

1234
# Vector of currencies curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') typeof(curr)
copy

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:

12345
curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') # Convert into factor curr_f <- factor(curr) curr_f
copy

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.

Tarefa

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:

  1. Display the values of the original vector blood.
  2. Convert blood into a factor and assign it to the variable blood_gr.
  3. Display the values of blood_gr.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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:

1234
# Vector of currencies curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') typeof(curr)
copy

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:

12345
curr <- c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR') # Convert into factor curr_f <- factor(curr) curr_f
copy

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.

Tarefa

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:

  1. Display the values of the original vector blood.
  2. Convert blood into a factor and assign it to the variable blood_gr.
  3. Display the values of blood_gr.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 1
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
some-alt