← Back to R Course | Chapter 3: Vectors | Lesson 2 of 7

c() Function क्या है

c function, जो combine का short है, single values या shorter lists को एक लंबे vector में glue करता है। यह एक chain पर beads clip करने जैसा है।

In this page:

  1. c() Function
Syntax
r
combined <- c(value1, value2, value3)
longer <- c(vector1, vector2)

c() Function

c() (combine) individual values से एक vector बनाता है या existing vectors को साथ merge करता है।

अगर values mixed types की हों, R इन सबको सबसे general common type में coerce करता है, जैसे अगर कोई element character हो तो numbers को strings में convert करना। अलग sources से data combine करते वक्त यह coercion rule याद रखना ज़रूरी है।

Warning: c(1, 2, "three") हर element को character में coerce करता है -- types mix करना silently पूरे vector को सबसे general type में promote कर देता है।

उदाहरण: The c() Function

markup
numbers <- c(1, 2, 3)
combined <- c(numbers, 4, 5)
print(combined)

mixed <- c(1, 2, "three")
print(mixed)
cat(class(mixed), "\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. यह भूल जाना कि c(1, 2, "three") हर element को एक string में बदल देता है, इसलिए इस पर 1 + 1 fail होता है।
  2. पहले vector को एक variable में store करने की बजाय c[1] इस्तेमाल करना जब function का नाम c है।
  3. एक variable का नाम c रखना, जो कुछ hide नहीं करता लेकिन code confusing बनाता है, जब functions और variables नाम share कर सकते हैं।
🔒

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.