R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
In R, the variable does not need to be declared by any specific type, and can change even type after setting:
my_var <- 30 # my_var is type of numeric
my_var <- "Sally"
# my_var is now of type character (aka string)
R has a wide range of data types and classes of objects. You will learn more about this as you get to know R.
Basic data types in R can be categorized into the following types:
numeric
- (10.5, 55, 787)integer
- (1L, 55L, 100L, where the letter "L" declares this as an integer)complex
- (9 + 3i, where "i" is the imaginary part)character
(a.k.a. string) - ("k", "R is exciting", "FALSE", "11.5")logical
(a.k.a. boolean) - (TRUE or FALSE)We can use the class()
function to test the variability of the data:
# numeric
x <- 10.5
class(x)
# integer
x <- 1000L
class(x)
#
complex
x <- 9i + 3
class(x)
# character/string
x <- "R is exciting"
class(x)
# logical/boolean
x <- TRUE
class(x)
You will learn more about each type of data in future chapters.