Published Jan 9, 2022
Contribute to Docs
R supports many data types, each with different uses and characteristics. Variables can hold different data types, and are not limited to storing the data type they were initially assigned.
# This is legal in R# Assign an integer data typevar1 <- 1L# Assign a string data typevar1 <- "Hello world!"
R supports the following basic data types:
numerictype for whole numbers or decimals. (5.12, 16)
integertype for whole numbers followed by an
complextype for numbers with an imaginary part, denoted by an
i. (5 + 7i)
charactertype for strings of characters. (“Hello World!”)
logicalfor Boolean values. (
class() function can be used to determine the data type of a variable.
x <- 3 + 2iclass(x) # Output: "complex"x <- 100class(x) # Output: "numeric"x <- 100Lclass(x) # Output: "integer"
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn R on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification