R Factors

  • factors are a data type used to represent variables that are in categories.
  • syntax–

Examples of factors

  • gender <- factor(c(“Male”, “Female”, “Male”, “Female”))
  • color <- factor(c(“Red”, “Blue”, “Green”, “Red”))
  • education <- factor(c(“High School”, “Bachelor’s”, “Master’s”, “Ph.D.”))
  • vehicle_type <- factor(c(“Sedan”, “SUV”, “Truck”, “Sedan”))
  • rating <- factor(c(“Low”, “Medium”, “High”, “Medium”), levels = c(“Low”, “Medium”, “High”))
  • eye_color <- factor(c(“Brown”, “Blue”, “Green”, “Brown”))

Syntax

Example

Example 2

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top