Skip to content

Instantly share code, notes, and snippets.

@BroVic
Created November 3, 2024 16:52
Show Gist options
  • Save BroVic/ab0db95eb3b7feb34d3417b4f2cadba6 to your computer and use it in GitHub Desktop.
Save BroVic/ab0db95eb3b7feb34d3417b4f2cadba6 to your computer and use it in GitHub Desktop.
Factors for neophytes
# 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