Map() का उपयोग
Map दो या ज़्यादा lists के आर-पार side by side चलता है और हर matching pair पर एक function apply करता है, हर बच्चे को इनके अपने name tag से pair करने की तरह। यह results की एक list वापस देता है।
In this page:
Syntax
Map(FUN, x, y)
Map()
Map(FUN, x, y, ...) parallel में दो या ज़्यादा vectors/lists के corresponding elements पर एक function apply करता है, दूसरी languages में zip-and-apply जैसा।
sapply() के उलट, जो एक single input पर iterate करता है, Map() element-wise कई inputs combine करने के लिए बना है। यह हमेशा lapply() की तरह एक list return करता है।
Note:
Map() वह तरीका है जिससे आप parallel में दो (या ज़्यादा) vectors के आर-पार एक function apply करते हैं -- sapply()/lapply() सिर्फ एक single input vector handle करते हैं।
उदाहरण: Map()
a <- c(1, 2, 3)
b <- c(10, 20, 30)
result <- Map(function(x, y) x + y, a, b)
print(result)
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. #}
आम गलतियां
Map()से एक vector वापस पाने की उम्मीद करना, जब यह एक list return करता है; flatten करने के लिएunlist()इस्तेमाल करें।- अलग lengths के vectors pass करना और recycling से surprised होना।
Map()को दूसरी languages केmapसे confuse करना, जब R में function पहले आता है।