← Back to R Course | Chapter 6: Strings | Lesson 1 of 7

paste और paste0

paste text के pieces को साथ glue करता है, train cars को एक train में जोड़ने की तरह। paste0 इसे बीच में बिना space के करता है, और आप अपना खुद का separator चुन सकते हैं।

In this page:

  1. paste और paste0
Syntax
r
paste(string1, string2, sep = " ")
paste0(string1, string2)
paste(vector_name, collapse = ", ")

paste और paste0

paste() strings को साथ concatenate करता है, हर argument के बीच एक separator (default से एक space) insert करते हुए। paste0(), paste(..., sep = "") का shorthand है, बिल्कुल बिना separator के concatenate करते हुए।

दोनों vectors पर भी element-wise काम करते हैं, corresponding elements pair करते हुए।

Note: paste0(a, b) बिना space के एक string बनाने का एक common shortcut है, जैसे एक file path या identifier।

उदाहरण: paste and paste0

markup
first <- "Hello"
second <- "World"

cat(paste(first, second), "\n")
cat(paste0(first, second), "\n")
cat(paste(first, second, sep = "-"), "\n")
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. यह उम्मीद करना कि paste("a", "b") में कोई space नहीं होगा, जब default separator एक space है; paste0() या sep = "" इस्तेमाल करें।
  2. एक vector pass करना और एक string की उम्मीद करना, जब paste() एक vector देता है और आपको collapse = ", " चाहिए।
  3. strings जोड़ने के लिए + इस्तेमाल करना, जो R में एक error है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 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.