2.1 Data Type
There are five basic data types:
- logical
- integer
- numeric
- complex
- character.
2.1.1 Logical
Logical data type can either be TRUE and FALSE. It corresponds to integer 0 and 1.
x <- TRUE
x
## [1] TRUE
y <- FALSE
y
## [1] FALSE
class(x)
## [1] "logical"
Note that We use the function class() to see the data type.
2.1.2 Integer
Integer data type covers all whole numbers. It is represented by number and letter L: 1L, 2L, 3L.
x <- 1L
x
## [1] 1
class(x)
## [1] "integer"
2.1.3 Numeric
Numeric data type covers all real numbers.
x <- 2.6
x
## [1] 2.6
class(x)
## [1] "numeric"
2.1.4 Complex
Complex data type covers all complex number.
x <- 2 +5i
x
## [1] 2+5i
class(x)
## [1] "complex"
2.1.5 Character
Character data type covers all text strings.
x <- "Hello World"
x
## [1] "Hello World"
class(x)
## [1] "character"