2.5 Data types

There are four common data types in R, they are numeric, logical, character and integer. All these data types can be used to create vectors natively.

#create a numeric vector x with 5 components
x<-c(1,3,2,10,5)
x
## [1]  1  3  2 10  5
#create a logical vector x
x<-c(TRUE,FALSE,TRUE)
x
## [1]  TRUE FALSE  TRUE
# create a character vector
x<-c("sds","sd","as")
x
## [1] "sds" "sd"  "as"
class(x)
## [1] "character"
# create an integer vector
x<-c(1L,2L,3L)
x
## [1] 1 2 3
class(x)
## [1] "integer"