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

Vector के Functions

Vector functions ready-made tools हैं जो एक साथ पूरी list देखते हैं, जैसे सब कुछ add करना या इसकी length ढूंढना। ये आपको यह हाथ से करने से बचाते हैं।

In this page:

  1. Vector Functions
Syntax
r
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

markup
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))
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. NA वाले एक vector पर sum call करना और NA पाना, जब na.rm = TRUE चाहिए।
  2. यह उम्मीद करना कि sort(v) v बदल देगा, जब यह एक sorted copy return करता है।
  3. 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:

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.