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

Numeric Type

Numeric is R's usual kind of number, able to hold decimals as well as whole values. It is the default whenever you type a number.

In this page:

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

Numeric Type

numeric is R's default type for any number, storing values as double-precision floating point regardless of whether they look like whole numbers.

Most arithmetic in R produces numeric results. Use class() or typeof() to check a value's actual type.

Note: Even x <- 5 (no decimal point) creates a numeric (double), not an integer, unless you explicitly use 5L.

Example: 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. #}
Common Mistakes
  1. Assuming 5 is an integer, when R stores it as a double so class(5) is "numeric".
  2. Comparing decimals with ==, as in 0.1 + 0.2 == 0.3, which is FALSE because of floating-point rounding; use all.equal().
  3. Expecting integer division from /, when 5 / 2 is 2.5 and you need %/% for 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.