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

Numeric Type क्या है

Numeric R का usual तरह का number है, whole values के साथ-साथ decimals भी hold करने में सक्षम। जब भी आप एक number type करें यह default है।

In this page:

  1. Numeric Type
Syntax
r
x <- 3.14
class(x)    # "numeric"

Numeric Type

numeric किसी भी number के लिए R का default type है, values को double-precision floating point की तरह store करते हुए चाहे वे whole numbers जैसी दिखें या नहीं।

R में ज़्यादातर arithmetic numeric results produce करता है। एक value का actual type check करने के लिए class() या typeof() इस्तेमाल करें।

Note: x <- 5 भी (कोई decimal point नहीं) एक numeric (double) बनाता है, एक integer नहीं, जब तक आप explicitly 5L इस्तेमाल न करें।

उदाहरण: Numeric Type

markup
x <- 5
y <- 5.5

cat(class(x), class(y), "\n")
cat(x + 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. यह मान लेना कि 5 एक integer है, जब R इसे एक double की तरह store करता है इसलिए class(5) "numeric" है।
  2. decimals को == से compare करना, जैसे 0.1 + 0.2 == 0.3, जो floating-point rounding की वजह से FALSE है; all.equal() इस्तेमाल करें।
  3. / से integer division की उम्मीद करना, जब 5 / 2 2.5 है और 2 के लिए आपको %/% चाहिए।
🔒

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.