Data types are an essential part of programming. The ability to identify the different data types in a programming language makes it easier for a programmer to code. The different data types mean that different data types can and can not do different things.
A variable helps store different data, which are of various types. We’ll look at the different data types in the R language in this shot.
There are five basic data types in R:
character: Strings. For example, 'Theo', 'R', '10', and so on.integer: Positive or negative. For example, 10L, -20L, 100L, and so on. The L tells R to store the value as an integer.numerical: Numbers. For example, 1, 10, 1000, and so on.logical: Boolean (TRUE or FALSE)complex: Complex numbers. For example, 5 + 2i, 10 - 5i, and so on.# charactername <- 'Theo'# integerx <- -10L# numericaly <- 200# logicala <- TRUE# complexz = 3 + 9inamexyaz
In the R language, we use the class() function to check the data type of a variable.
# charactername <- 'Theo'# integerx <- -10L# numericaly <- 200# logicala <- TRUE# complexz = 3 + 9iclass(name)class(x)class(y)class(a)class(z)