base::match()
is not a generic, so we can't just define Arrow methods for
it. This function exposes the analogous functions in the Arrow C++ library.
match_arrow(x, table, ...) is_in(x, table, ...)
x |
|
---|---|
table |
|
... | additional arguments, ignored |
match_arrow()
returns an int32
-type Arrow object of the same length
and type as x
with the (0-based) indexes into table
. is_in()
returns a
boolean
-type Arrow object of the same length and type as x
with values indicating
per element of x
it it is present in table
.
# note that the returned value is 0-indexed cars_tbl <- Table$create(name = rownames(mtcars), mtcars) match_arrow(Scalar$create("Mazda RX4 Wag"), cars_tbl$name)#> Scalar #> 1is_in(Array$create("Mazda RX4 Wag"), cars_tbl$name)#> Array #> <bool> #> [ #> true #> ]# Although there are multiple matches, you are returned the index of the first # match, as with the base R equivalent match(4, mtcars$cyl) # 1-indexed#> [1] 3match_arrow(Scalar$create(4), cars_tbl$cyl) # 0-indexed#> Scalar #> 2# If `x` contains multiple values, you are returned the indices of the first # match for each value. match(c(4, 6, 8), mtcars$cyl)#> [1] 3 1 5#> Array #> <int32> #> [ #> 2, #> 0, #> 4 #> ]#> Array #> <bool> #> [ #> true, #> true, #> true #> ]is_in(Scalar$create(4), mtcars$cyl) # returns Scalar#> Scalar #> true#> Array #> <bool> #> [ #> true, #> true, #> true #> ]#> ChunkedArray #> [ #> [ #> true, #> true #> ], #> [ #> true #> ] #> ]