March 2018
Beginner to intermediate
570 pages
13h 42m
English
So far, we've only been dealing with numerics, but there are other atomic data types in R:
> foo <- TRUE # foo is of the logical data type > class(foo) # class() tells us the type [1] "logical" > bar <- "hi!" # bar is of the character data type > class(bar) [1] "character"
The logical data type (also called Booleans) can hold the values TRUE or FALSE or, equivalently, T or F. The familiar operators from Boolean algebra are defined for these types:
> foo [1] TRUE > foo && TRUE # boolean and [1] TRUE > foo && FALSE [1] FALSE > foo || FALSE # boolean or [1] TRUE > !foo # negation operator [1] FALSE
In a Boolean expression with a logical value and a number, any number that is not 0 is interpreted as TRUE: