Logical Type क्या है
एक logical value बस TRUE या FALSE है, एक light switch की तरह जो on या off है। R इसे yes-or-no questions answer करने के लिए इस्तेमाल करता है।
In this page:
Syntax
flag <- TRUE
result <- value1 > value2 # logical result
Logical Type
logical type TRUE या FALSE (या इनके shorthand T/F) hold करता है, और हर comparison का result है।
Logical values arithmetic में इस्तेमाल होने पर 1 (TRUE) और 0 (FALSE) की तरह behave करते हैं, जो sum() से TRUE values count करने को एक common idiom बनाता है। ==, <, > जैसे comparison operators हमेशा logical results produce करते हैं।
Note:
sum(logical_vector) count करता है कितने elements TRUE हैं, क्योंकि arithmetic में TRUE को 1 treat किया जाता है।उदाहरण: Logical Type
is_active <- TRUE
is_admin <- FALSE
cat(class(is_active), "\n")
cat(is_active + is_active, "\n") # TRUE + TRUE = 2
cat(10 > 5, "\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. #}
आम गलतियां
TRUEकी बजायtrueयाTrueलिखना, जिसे R नहीं पहचानता।TऔरFको ऐसे इस्तेमाल करना जैसे वे reserved हों, जब वे ordinary variables हैं जिन्हें overwrite किया जा सकता है।- compare करते वक्त
==की बजाय=इस्तेमाल करना, जो assign करता है या एकTRUE/FALSEकी बजाय एक error देता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: