Search notes:

R: set operations

The set operations in R are:
They operate on two vectors.
The result will not contain any duplicate values.
set_1 = c('the', 'foo', 'the', 'bar', 'and', 'the', 'baz')
set_2 = c('The', 'Foo', 'the', 'Bar', 'and', 'the', 'Baz')

union (set_1, set_2)
# [1] "the" "foo" "bar" "and" "baz" "The" "Foo" "Bar" "Baz"

intersect (set_1, set_2)
# [1] "the" "and"

setdiff (set_1, set_2)
# [1] "foo" "bar" "baz"

# { setequal

set_a <- c('Foo', 'Bar', 'Baz'  )
set_c <- c('Bar', 'Baz', 'Foo'  )

setequal(set_a, set_c)
# [1] TRUE

# }

# { identical

set_a <- c('Bar', 'Baz', 'Foo'  )
set_b <- c('Baz', 'Foo', 'Bar'  )

identical(set_a, set_b)
# [1] FALSE

# }

# { is.element

is.element( 5, 1:10)
# [1] TRUE

is.element(15, 1:10)
# [1] FALSE

# }
Github repository about-r, path: /examples/set_operations.R

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745487454, '18.222.107.172', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/_set-operations(87): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78