Created
November 3, 2024 16:52
-
-
Save BroVic/ab0db95eb3b7feb34d3417b4f2cadba6 to your computer and use it in GitHub Desktop.
Factors for neophytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a vector of industry types with 10 elements | |
# This vector will be a character vector | |
industryType <- c("small", "medium", "small", "large", "large", "medium", "small", "small", "medium", "large") | |
industryType | |
length(industryType) | |
# Change it into a factor | |
industryCategory <- factor(industryType) | |
industryCategory | |
# Examine the structure of these 2 objects | |
str(industryType) | |
str(industryCategory) | |
# Check the levels | |
levels(industryCategory) | |
is.integer(industryCategory) | |
is.factor(industryCategory) | |
is.factor(industryType) | |
as.integer(industryCategory) | |
as.integer(industryType) | |
typeof(industryType) | |
typeof(industryCategory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment