ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

R Statistical Programming Tutorial• 5 min read

Factors & Categorical Variables

Represent categorical data (e.g. Treatment vs Control, Low/Med/High) with statistical factor levels.

Why Factors Outperform Strings

In statistical modeling, string text must be mapped to discrete levels. Calling factor(vector, levels = c("Low", "Med", "High")) allows regression algorithms to construct dummy contrast matrices automatically.

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which R function converts a character vector into a statistical categorical variable with distinct levels?