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"