Logical Indexing क्या है
Logical indexing सिर्फ वे items रखता है जो एक true-or-false test pass करते हैं, एक sieve की तरह जो सिर्फ आपकी चाही चीज़ें through होने देता है। आप rule describe करते हैं और R list filter करता है।
In this page:
Syntax
vector_name[vector_name > value]
vector_name[condition]
Logical Indexing
एक vector को same length के एक logical vector से index किया जा सकता है, सिर्फ वे elements select करते हुए जहाँ corresponding value TRUE हो।
यह आमतौर पर एक comparison से बनाया जाता है, जैसे v[v > 5], एक condition के आधार पर एक vector filter करने के लिए। Logical indexing R के सबसे powerful और अक्सर इस्तेमाल होने वाले idioms में से एक है।
Note:
v[v > 5] लगभग English जैसा पढ़ा जाता है: "मुझे v के वे elements दो जो 5 से बड़े हैं"।
उदाहरण: Logical Indexing
v <- c(2, 8, 5, 10, 3)
print(v > 5)
print(v[v > 5])
evens <- v[v %% 2 == 0]
print(evens)
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. #}
आम गलतियां
- एक vector पर एक comma के साथ
v[v > 5, ]लिखना, जो incorrect dimensions के बारे में एक error देता है। v[v > 2 && v < 8]में&की जगह&&इस्तेमाल करना, जो सिर्फ पहला element इस्तेमाल करता है और, recent R versions में, एक error देता है।- vector में
NAvalues होना, इसलिएv[v > 5]उन positions के लिएNAentries return करता है।
चैप्टर सारांश
- Vectors एक type की कई values hold करते हैं,
c()और दूसरे constructors से बने। - Vector arithmetic एक साथ पूरे vectors पर काम करता है, और indexing position, name, या logical condition से elements select करता है।
- Named vectors और vector functions आपको data label और summarize करने में मदद करते हैं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: