INTRODUCTION TO R
Basic Data Types
Introduction to R
logical
> TRUE
[1] TRUE
> class(TRUE)
[1] "logical"
> FALSE
[1] FALSE
> class(NA)
[1] "logical"
> T
[1] TRUE
> F
[1] FALSE
class() to reveal type
Introduction to R
numeric
> 2
[1] 2
> 2.5
[1] 2.5
> 2L
[1] 2
> class(2)
[1] "numeric"
> class(2L)
[1] "integer"
Introduction to R
numeric
> [Link](2)
[1] TRUE
> [Link](2L)
[1] TRUE
> [Link](2)
[1] FALSE
> [Link](2L)
[1] TRUE
integer is numeric
numeric not always integer
Introduction to R
character
> "I love data science!"
[1] "I love data science!"
> class("I love data science!")
[1] "character"
Introduction to R
Other atomic types
double: higher precision
complex: complex numbers
raw: store raw bytes
Introduction to R
Coercion
> [Link](TRUE)
[1] 1
> [Link](FALSE)
[1] 0
> [Link](4)
[1] "4"
> [Link]("4.5")
[1] 4.5
> [Link]("4.5")
[1] 4
> [Link]("Hello")
[1] NA
Warning message:
NAs introduced by coercion
INTRODUCTION TO R
Lets practice!