Vector की Indexing
Vector indexing एक list से items इनकी position से पिक करता है, और R एक से count करना शुरू करता है। यह एक shelf पर तीसरी book माँगने जैसा है।
In this page:
Syntax
vector_name[index]
vector_name[c(index1, index2)]
vector_name[-index]
vector_name[start:end]
Vector Indexing
R vectors 0 से नहीं, 1 से index होते हैं, v[3] जैसे square brackets इस्तेमाल करते हुए। आप एक साथ कई elements निकालने के लिए positions के एक vector से भी index कर सकते हैं, जैसे v[c(1, 3)]।
v[-1] जैसे Negative indices उस position को select करने की बजाय exclude करते हैं।
Warning:
R indexing 0 से नहीं, 1 से शुरू होती है -- v[1] पहला element है, ज़्यादातर दूसरी programming languages के उलट।
उदाहरण: Vector Indexing
v <- c(10, 20, 30, 40, 50)
cat(v[1], "\n")
print(v[c(1, 3)])
print(v[-1])
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. #}
आम गलतियां
- पहले index की तरह 0 इस्तेमाल करना, जब
v[0]एक empty vector return करता है और पहला elementv[1]है। v[-1]इस्तेमाल करना और last element की उम्मीद करना, जब यह पहला हटाता है और बाकी return करता है।- length से आगे index करना, जैसे
v[10], जोNAreturn करता है error नहीं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: