tapply() का उपयोग
tapply numbers को एक label से groups में split करता है और हर group के लिए कुछ calculate करता है, हर class की average height की तरह। यह एक group-by-group calculator है।
In this page:
Syntax
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()
scores <- c(90, 85, 70, 60, 95)
groups <- c("A", "A", "B", "B", "A")
averages <- tapply(scores, groups, mean)
print(averages)
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. #}
आम गलतियां
- data से अलग length के groups pass करना, जो एक error देता है।
tapply()से एक data frame की उम्मीद करना, जब यह names वाला एक array return करता है; एक data frame के लिएaggregate()इस्तेमाल करें।- values में
NAignore करना, इसलिए एक group का meanNAबन जाता है जब तकna.rm = TRUEpass न हो।