Data Types
StevenSwiniarski474 total contributions
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
numeric
type for whole numbers or decimals. (5.12, 16) - The
integer
type for whole numbers followed by anL
. (100L) - The
complex
type for numbers with an imaginary part, denoted by ani
. (5 + 7i) - The
character
type for strings of characters. (“Hello World!”) - The
logical
for Boolean values. (TRUE
orFALSE
)
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"
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.