← Back to R Course | Chapter 11: Apply Family | Lesson 4 of 6

tapply() का उपयोग

tapply numbers को एक label से groups में split करता है और हर group के लिए कुछ calculate करता है, हर class की average height की तरह। यह एक group-by-group calculator है।

In this page:

  1. tapply()
Syntax
r
tapply(x, index, FUN)

tapply()

tapply(x, index, FUN) एक vector के subsets पर एक function apply करता है, एक second vector (index) से grouped, spirit में aggregate() जैसा लेकिन data frames की बजाय सीधे vectors पर काम करते हुए।

यह पहले एक पूरी data frame बनाए बिना एक per-group statistic compute करने का एक compact तरीका है। Result distinct group values से indexed एक array है।

Note: tapply() aggregate() का vector-based equivalent है -- जब आपके पास पहले से एक data frame न हो इसके लिए reach करें।

उदाहरण: tapply()

markup
scores <- c(90, 85, 70, 60, 95)
groups <- c("A", "A", "B", "B", "A")

averages <- tapply(scores, groups, mean)
print(averages)
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. data से अलग length के groups pass करना, जो एक error देता है।
  2. tapply() से एक data frame की उम्मीद करना, जब यह names वाला एक array return करता है; एक data frame के लिए aggregate() इस्तेमाल करें।
  3. values में NA ignore करना, इसलिए एक group का mean NA बन जाता है जब तक na.rm = TRUE pass न हो।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 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.