merge() का उपयोग
merge दो tables को एक column से जोड़ता है जो वे share करती हैं, students को इनके ID number से grades से match करने की तरह। यह related information को एक table में सीता है।
In this page:
Syntax
merged <- merge(df1, df2, by = "key_column")
merge()
merge(df1, df2, by = "key") एक shared column के आधार पर दो data frames साथ जोड़ता है, एक SQL join जैसा।
Default से यह एक inner join perform करता है, दोनों frames में matching keys वाली सिर्फ rows रखते हुए; all = TRUE इसकी बजाय एक full outer join perform करता है। यह कई tables में फैले related data combine करने का standard तरीका है।
Note:
एक left join के लिए all.x = TRUE set करें (पहली data frame से हर row रखें, matched हो या नहीं)।
उदाहरण: merge()
people <- data.frame(id = c(1, 2, 3), name = c("Alice", "Bob", "Cara"))
scores <- data.frame(id = c(1, 2), score = c(95, 82))
merged <- merge(people, scores, by = "id")
print(merged)
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. #}
आम गलतियां
by.xऔरby.yके बिना हर data frame में अलग names वाले एक column पर merge करना, इसलिए R उन columns इस्तेमाल करने की कोशिश करता है जो match नहीं करते।- यह उम्मीद करना कि unmatched rows रखी जाएँगी, जब default सिर्फ matches रखता है; बाकी रखने के लिए
all = TRUEइस्तेमाल करें। - duplicate keys वाले एक column पर merge करना, जो rows multiply कर देता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: