Factors क्या हैं
एक factor एक fixed set से categories store करता है, जैसे T-shirt sizes small, medium, और large। R allowed choices और इनके order का track रखता है।
In this page:
Syntax
factor_name <- factor(c("level1", "level2"), levels = c("level1", "level2"))
levels(factor_name)
Factors
एक factor categorical data represent करता है जिसमें possible values का एक fixed, known set हो (levels कहलाता है), जैसे "low", "medium", "high"।
Factors factor() से बनते हैं और data को plain strings से ज़्यादा efficiently store करते हैं और साथ ही categories का proper statistical treatment भी enable करते हैं। levels() उन distinct categories की list करता है जो एक factor ले सकता है।
Note:
जब categories का एक meaningful order हो, जैसे small < medium < large, factor(x, levels = c(...), ordered = TRUE) इस्तेमाल करें।
उदाहरण: Factors
sizes <- factor(c("small", "large", "medium", "small"),
levels = c("small", "medium", "large"))
print(sizes)
print(levels(sizes))
print(table(sizes))
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
as.numeric(f)से numbers का एक factor convert करना, जो original values नहीं बल्कि level codes return करता है।- एक ऐसी value assign करना जो levels में से एक न हो, जैसे
sizes[1] <- "huge", जो एक warning के साथNAदेता है। levelsको order में set करना भूल जाना, इसलिए "large" alphabetically "medium" और "small" से पहले sort होता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: