← Back to R Course | Chapter 2: Variables & Types | Lesson 5 of 7

Logical Type क्या है

एक logical value बस TRUE या FALSE है, एक light switch की तरह जो on या off है। R इसे yes-or-no questions answer करने के लिए इस्तेमाल करता है।

In this page:

  1. Logical Type
Syntax
r
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

markup
is_active <- TRUE
is_admin <- FALSE

cat(class(is_active), "\n")
cat(is_active + is_active, "\n")  # TRUE + TRUE = 2
cat(10 > 5, "\n")
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. TRUE की बजाय true या True लिखना, जिसे R नहीं पहचानता।
  2. T और F को ऐसे इस्तेमाल करना जैसे वे reserved हों, जब वे ordinary variables हैं जिन्हें overwrite किया जा सकता है।
  3. compare करते वक्त == की बजाय = इस्तेमाल करना, जो assign करता है या एक TRUE / FALSE की बजाय एक error देता है।
🔒

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.