Vector के Functions
Vector functions ready-made tools हैं जो एक साथ पूरी list देखते हैं, जैसे सब कुछ add करना या इसकी length ढूंढना। ये आपको यह हाथ से करने से बचाते हैं।
In this page:
Syntax
length(vector_name)
sum(vector_name)
mean(vector_name)
max(vector_name)
sort(vector_name)
Vector Functions
R एक साथ पूरे vector पर operate करने वाले कई built-in functions देता है, जैसे sum(), length(), max(), min(), और sort()।
ये typically optimized C code में implement होते हैं और एक equivalent manual loop से कहीं तेज़ चलते हैं। इन functions को सीखना concise, idiomatic R लिखने की key है।
Note:
एक manual for-loop लिखने से पहले sum() या sort() जैसे एक built-in vector function के लिए reach करें -- almost हमेशा एक exist करता है।
उदाहरण: Vector Functions
v <- c(5, 3, 8, 1, 9)
cat("Sum:", sum(v), "\n")
cat("Max:", max(v), "\n")
cat("Min:", min(v), "\n")
print(sort(v))
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. #}
आम गलतियां
NAवाले एक vector परsumcall करना औरNAपाना, जबna.rm = TRUEचाहिए।- यह उम्मीद करना कि
sort(v)vबदल देगा, जब यह एक sorted copy return करता है। - element by element compare करने के लिए
max(v1, v2)इस्तेमाल करना, जब यह एक maximum return करता है;pmax()इस्तेमाल करें।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: