which() का उपयोग
which आपको बताता है वे positions जहाँ एक condition true है, 'कौन-सी seats भरी हैं?' पूछने की तरह। यह आपको answers की बजाय seat numbers देता है।
In this page:
Syntax
which(condition)
vector_name[which(condition)]
which()
which(condition) *indices* return करता है जहाँ एक logical vector TRUE हो, values खुद नहीं।
यह तब useful है जब आपको matching elements की position जाननी हो, सिर्फ इन्हें filter नहीं करना। which.max() और which.min() सबसे बड़े/छोटे value का index ढूंढने के लिए shortcuts हैं।
Note:
which.max(v), which(v == max(v))[1] का एक shortcut है, एक call में सबसे बड़ी value की position ढूंढते हुए।
उदाहरण: which()
v <- c(3, 7, 2, 9, 4)
print(which(v > 4))
cat("Index of max value:", which.max(v), "\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. #}
आम गलतियां
- यह उम्मीद करना कि
which(v > 4)values return करेगा, जब यह इनकी positions return करता है; values के लिएv[v > 4]इस्तेमाल करें। which.max(v)इस्तेमाल करना और ties की सारी positions की उम्मीद करना, जब यह सिर्फ पहली return करता है।- यह भूल जाना कि condition में
NAvalueswhich()से ignore होती हैं, इसलिए वे silently drop हो जाती हैं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: