c() Function क्या है
c function, जो combine का short है, single values या shorter lists को एक लंबे vector में glue करता है। यह एक chain पर beads clip करने जैसा है।
In this page:
Syntax
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
numbers <- c(1, 2, 3)
combined <- c(numbers, 4, 5)
print(combined)
mixed <- c(1, 2, "three")
print(mixed)
cat(class(mixed), "\n")
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. #}
आम गलतियां
- यह भूल जाना कि
c(1, 2, "three")हर element को एक string में बदल देता है, इसलिए इस पर1 + 1fail होता है। - पहले vector को एक variable में store करने की बजाय
c[1]इस्तेमाल करना जब function का नामcहै। - एक variable का नाम
cरखना, जो कुछ hide नहीं करता लेकिन code confusing बनाता है, जब functions और variables नाम share कर सकते हैं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: