apply() Family का परिचय
apply family tools का एक set है जो एक साथ कई items पर एक function चलाते हैं, एक teacher की तरह जो हर paper को same rules से mark करता है। यह lesson आपको इनकी पहली झलक देता है।
In this page:
Syntax
apply(matrix_name, MARGIN, FUN)
lapply(x, FUN)
sapply(x, FUN)
apply() Family (Preview)
R के apply family के functions (apply, lapply, sapply, और बाकी) एक explicit loop लिखे बिना एक data structure के elements के आर-पार एक function apply करते हैं, और एक बाद के chapter में depth में cover होते हैं।
apply(m, 1, sum) एक matrix की हर row के आर-पार sum apply करता है। यह preview dedicated Apply Family chapter गहराई में जाने से पहले concept introduce करता है।
Note:
apply() का दूसरा argument, 1 या 2, control करता है कि function एक matrix के row से apply हो या column से।
उदाहरण: The apply() Family (Preview)
m <- matrix(1:6, nrow = 2)
row_sums <- apply(m, 1, sum)
col_sums <- apply(m, 2, sum)
print(row_sums)
print(col_sums)
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. #}
आम गलतियां
apply(m, 1, sum)rows के लिए और2columns के लिए गलत तरीके से इस्तेमाल करना, इसलिए results swap हो जाते हैं।- mixed types वाले एक data frame पर
applyइस्तेमाल करना, जो इसे एक character matrix में convert कर देता है। - यह उम्मीद करना कि
sapplyऔरlapplysame type देंगे, जबlapplyहमेशा एक list return करता है।
चैप्टर सारांश
- Matrices, arrays, lists, data frames, और factors R की main data structures हैं।
- Data frames tabular data hold करते हैं, और lists mixed types hold कर सकते हैं।
which()positions ढूंढता है, और structures के आर-पार काम करने के लिएapply()functions preview किए गए।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: