# Logical Operations

• TODO: intro

After reading these notes you should be able to:

• TODO: learning objectives

## Comparison Operators

Spring 2022 Readers: Dave tried to write too many notes this week. Please read the following in place of this under construction section:

• TODO: note about odd naming
• TODO: change to “comparison” operators?
• TODO: table of operators and meanings
• TODO: These will produce logical values
``?Comparison``
``?`%in%```
• TODO: `indentical()`, `all.equal()`
``1 == 1L``
``[1] TRUE``
``identical(1, 1L)``
``[1] FALSE``
``0.1 + 0.2 == 0.3``
``[1] FALSE``
``all.equal(0.1 + 0.2, 0.3)``
``[1] TRUE``

## Boolean Operations

Spring 2022 Readers: Dave tried to write too many notes this week. Please read the following in place of this under construction section:

• TODO: these are operations on logic values (they often work on numeric values, expect coercion)
• TODO: https://en.m.wikipedia.org/wiki/Truth_table
``?base::Logic``
• TODO: vector in, vector out, vs vector in, vector of length one out
``?any``
``?all``
``````x = c(TRUE, TRUE, FALSE, FALSE)
y = c(TRUE, FALSE, TRUE, FALSE)
data.frame(
x = x,
y = y,
`!x` = !x, # not
`x & y` = x & y, # and
`x | y` = x | y, # or
`xor(x, y)` = xor(x, y), # exclusive or
check.names = FALSE
)``````
``````      x     y    !x x & y x | y xor(x, y)
1  TRUE  TRUE FALSE  TRUE  TRUE     FALSE
2  TRUE FALSE FALSE FALSE  TRUE      TRUE
3 FALSE  TRUE  TRUE FALSE  TRUE      TRUE
4 FALSE FALSE  TRUE FALSE FALSE     FALSE``````

## Logical Subsetting

Spring 2022 Readers: Dave tried to write too many notes this week. Please read the following in place of this under construction section:

• TODO: proportion between example
• TODO: example with data frames rows

## Summary

• TODO: You’ve learned to…

## What’s Next?

• TODO: control flow, etc.

## TODO

• TODO: `?intersect`
• TODO: `which`