An R Introduction to Statistics

Logical

A logical value is often created via comparison between variables.

> x = 1; y = 2   # sample values 
> z = x > y      # is x larger than y? 
> z              # print the logical value 
[1] FALSE 
> class(z)       # print the class name of z 
[1] "logical"

Standard logical operations are "&" (and), "|" (or), and "!" (negation).

> u = TRUE; v = FALSE 
> u & v          # u AND v 
[1] FALSE 
> u | v          # u OR v 
[1] TRUE 
> !u             # negation of u 
[1] FALSE

Further details and related logical operations can be found in the R documentation.

> help("&")