R Data Types
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:
- The
numerictype for whole numbers or decimals. (5.12, 16) - The
integertype for whole numbers followed by anL. (100L) - The
complextype for numbers with an imaginary part, denoted by ani. (5 + 7i) - The
charactertype for strings of characters. (“Hello World!”) - The
logicalfor Boolean values. (TRUEorFALSE)
The 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"
Contribute to Docs
- 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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to code and clean and manipulate data for analysis and visualization with the R programming language.
- Beginner Friendly.14 hours