0
0
R Programmingprogramming~5 mins

Why factors represent categorical data in R Programming - Quick Recap

Choose your learning style9 modes available
Recall & Review
beginner
What is a factor in R?
A factor in R is a data type used to represent categorical data by storing values as levels, which are distinct categories.
Click to reveal answer
beginner
Why are factors useful for categorical data?
Factors store categories as levels, which helps R handle and analyze categorical data efficiently, like grouping or summarizing.
Click to reveal answer
intermediate
How do factors differ from character vectors in R?
Factors have fixed levels representing categories, while character vectors are just strings without category information.
Click to reveal answer
intermediate
What happens if you try to add a new category to a factor without updating levels?
R will not recognize the new category and may convert it to NA (missing value) because it is not in the factor's levels.
Click to reveal answer
beginner
How can you convert a character vector to a factor in R?
Use the function factor() to convert a character vector into a factor with levels representing unique categories.
Click to reveal answer
What does a factor in R represent?
ANumeric data with decimals
BCategorical data with fixed levels
CText data without categories
DLogical TRUE or FALSE values
What happens if you assign a value not in the factor levels?
AIt causes an error and stops the program
BIt is automatically added as a new level
CIt becomes NA (missing value)
DIt is converted to a number
Which function converts a character vector to a factor?
Aas.character()
Bc()
Clevels()
Dfactor()
Why are factors better than characters for categorical data?
AThey store categories as levels for efficient analysis
BThey use less memory for numbers
CThey allow decimals in categories
DThey automatically sort data alphabetically
What type of data is best represented by factors?
AData with distinct groups or categories
BContinuous numeric data
CFree text data
DDate and time data
Explain why factors are used to represent categorical data in R.
Think about how R stores and handles groups of data.
You got /4 concepts.
    Describe what happens if you try to add a new category to a factor without updating its levels.
    Consider how factors restrict values to predefined categories.
    You got /3 concepts.