Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Logical

Objects of type logical take on the values TRUE or FALSE. The basic logical operators include:

! Not $<$ Less than $<=$ Less than or equal to
$==$ Equal to $>$ Greater than $>=$ Greater than or equal to
& And | Or && || Non vectorised versions



> 5 == 4        # FALSE
> 5 != 4 	# TRUE
> ! 1 - 1	# TRUE since 1-1 is 0 and is coerced to FALSE
> TRUE * 2	# 2 since TRUE is coerced to 1.

The single logical connectives & and | operates on vectors, whilst the double connective returns a single result, and does a minimal amount of comparison to get the result.

> c(TRUE, TRUE, FALSE) & c(TRUE, FALSE, FALSE)
[1]  TRUE FALSE FALSE
> c(TRUE, TRUE, FALSE) && c(TRUE, FALSE, FALSE)
[1] TRUE

The double form is usually what you want in an if statement.



Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.