Factors Flashcards

1
Q

What is a factor?

A

A data type used to hold categorical variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the function to create an unordered factor?

A

factor()

Ex: factor_sex_vector <- factor(c(“Male”,”Female”,”Female”,”Male”,”Male”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a nominal categorical variable, and what is an ordinal categorical variable?

A

A nominal variable is a categorical variable without an implied order.

An ordinal variable is a categorical variable with a natural ordering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a factor level?

A

An individual category, such as “Male”, or “Green”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which function lets you change the names of factor levels?

A

levels()

Ex: levels(factor_vector) <- c(“name1”, “name2”,…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If you don’t specify the levels of the factor when creating the vector, how will R assign them?

A

Alphabetically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which function gives you a quick overview of the contents of a variable?

A

summary()

Ex: summary(my_var)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when you compare elements of a factor?

A

If the factor levels are nominal, R returns a warning message, telling you that comparisons are not meaningful.

If the factor levels are ordinal, they are compared by the order they were put in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the function to create an ordered factor?

A

factor()

Ex: factor(some_vector, ordered = TRUE, levels = c(“slow”, “medium” …))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the arguments to factor() when creating an ordered factor, aside from the collection of elements, and what do they do?

A

The argument ordered determines whether the factors are nominal or ordinal.

The argument levels gives the values of the factor the correct order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly