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

Integer Type क्या है

एक integer बिना decimals का एक whole number है, इसके बाद एक L से mark किया हुआ। यह बिना slices के पूरे apples count करने जैसा है।

In this page:

  1. Integer Type
Syntax
r
x <- 5L
class(x)    # "integer"

Integer Type

एक explicit integer एक L suffix से बनता है, जैसे 5L, default numeric (double) type से अलग। Integers कम memory इस्तेमाल करते हैं और useful हैं जब एक value guaranteed एक whole number हो, जैसे एक index या count।

is.integer() check करता है कि एक value specifically integer type की है या नहीं।

Note: बिना L suffix के, 5 एक double है, integer नहीं, भले ही यह एक whole number जैसा दिखे।

उदाहरण: Integer Type

markup
x <- 5L
y <- 5

cat(class(x), class(y), "\n")
cat(is.integer(x), is.integer(y), "\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. x <- 5 लिखना और एक integer की उम्मीद करना, जब सिर्फ 5L एक integer बनाता है।
  2. 5.5L जैसे एक decimal में L add करना, जो एक warning देता है और numeric रहता है।
  3. .Machine$integer.max + 1L जैसे एक integer को overflow करना, जो एक warning के साथ NA देता है।
🔒

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.