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

Integer Type

In this page:

  1. Integer Type

Integer Type

An explicit integer is created with an L suffix, like 5L, distinct from the default numeric (double) type. Integers use less memory and are useful when a value is guaranteed to be a whole number, such as an index or count. is.integer() checks whether a value is specifically of integer type.

Note: Without the L suffix, 5 is a double, not an integer, even though it looks like a whole number.

Example: Integer Type

markup
x <- 5L
y <- 5

cat(class(x), class(y), "\n")
cat(is.integer(x), is.integer(y), "\n")
🔒

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.