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

Map() का उपयोग

Map दो या ज़्यादा lists के आर-पार side by side चलता है और हर matching pair पर एक function apply करता है, हर बच्चे को इनके अपने name tag से pair करने की तरह। यह results की एक list वापस देता है।

In this page:

  1. Map()
Syntax
r
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()

markup
a <- c(1, 2, 3)
b <- c(10, 20, 30)

result <- Map(function(x, y) x + y, a, b)
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. Map() से एक vector वापस पाने की उम्मीद करना, जब यह एक list return करता है; flatten करने के लिए unlist() इस्तेमाल करें।
  2. अलग lengths के vectors pass करना और recycling से surprised होना।
  3. Map() को दूसरी languages के map से confuse करना, जब R में function पहले आता है।
🔒

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.