Implements the %in% operator for dbMatrix objects. This operator checks if
elements from the left operand are contained in the right operand, returning
a logical vector.
Details
This is a method for the standard %in% operator for dbMatrix objects.
It follows R's standard behavior for the %in% operator:
When
xis a dbDenseMatrix, it returns a logical vector with the same length as the total number of elements in the matrix.When
tableis a dbDenseMatrix, it allows checking if elements inxare in the matrix.For dbSparseMatrix objects, it throws an error to match the behavior of dgCMatrix.
Examples
con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
mat <- matrix(1:9, nrow = 3, ncol = 3)
dbmat <- dbMatrix(
value = mat,
con = con,
name = "example_matrix",
class = "dbDenseMatrix",
overwrite = TRUE
)
dbmat %in% c(1, 3, 5, 7, 9)
#> [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
c(1, 3, 5, 7, 9) %in% dbmat
#> [1] TRUE TRUE TRUE TRUE TRUE
DBI::dbDisconnect(con, shutdown = TRUE)