← Back to R Course | Chapter 8: Data Manipulation | Lesson 7 of 7

aggregate() का उपयोग

aggregate एक table को एक category से group करता है और हर group के लिए एक summary calculate करता है, हर class का average score ढूंढने की तरह। यह आपको हाथ से sort करने और add करने से बचाता है।

In this page:

  1. aggregate()
Syntax
r
aggregate(value ~ group, data = df, FUN = function_name)

aggregate()

aggregate(value ~ group, data = df, FUN = mean) एक data frame को एक column से group करता है और प्रति group एक summary statistic compute करता है (जैसे mean या sum), SQL के GROUP BY जैसा।

More specialized packages introduce होने से पहले यह group-wise summarization के लिए standard R base function है। Formula syntax, value ~ group, "value, grouped by group" की तरह पढ़ी जाती है।

Note: Formula syntax value ~ group naturally "summarize value, grouped by group" की तरह पढ़ी जाती है।

उदाहरण: aggregate()

markup
df <- data.frame(
  team = c("A", "A", "B", "B"),
  score = c(10, 20, 30, 40)
)

result <- aggregate(score ~ team, data = df, FUN = mean)
print(result)
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. #}
आम गलतियां
  1. formula को गलत direction में लिखना जैसे team ~ score, जब value left पर जाती है और group right पर।
  2. FUN = mean भूल जाना, या parentheses के साथ mean() pass करना, जो इसे तुरंत call कर देता है।
  3. values में NA होना, इसलिए mean NA है जब तक rows drop न हों या na.rm = TRUE pass न हो।
चैप्टर सारांश
  • Data CSV files जैसी files से पढ़ा और इनमें लिखा जाता है।
  • subset(), merge(), और order() data filter, combine, और sort करते हैं।
  • table() और aggregate() data summarize करते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.