You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by th...@apache.org on 2021/11/03 09:54:50 UTC
[arrow-cookbook] branch main updated: ARROW-13752 [Doc][Cookbook]
Searching for values matching a predicate in Arrays - R (#96)
This is an automated email from the ASF dual-hosted git repository.
thisisnic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new edf8308 ARROW-13752 [Doc][Cookbook] Searching for values matching a predicate in Arrays - R (#96)
edf8308 is described below
commit edf830843e88ce183165e8c667b9bf34c3fa58e4
Author: Nic Crane <th...@gmail.com>
AuthorDate: Wed Nov 3 09:54:45 2021 +0000
ARROW-13752 [Doc][Cookbook] Searching for values matching a predicate in Arrays - R (#96)
* Add in extra recipes
* Rephrase to make more idiomatic
---
r/content/arrays.Rmd | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/r/content/arrays.Rmd b/r/content/arrays.Rmd
index 2544cb1..ae353fe 100644
--- a/r/content/arrays.Rmd
+++ b/r/content/arrays.Rmd
@@ -8,7 +8,28 @@ represent a single column of data, with all values having the same data type.
A number of base R functions which have S3 generic methods have been implemented
to work on Arrow Arrays; for example `mean`, `min`, and `max`.
-## Computing Mean/Min/Max, etc value of an Array
+## Filter by values matching a predicate or mask
+
+You want to search for values in an Array that match a predicate condition.
+
+### Solution
+
+```{r, array_predicate}
+my_values <- Array$create(c(1:5, NA))
+my_values[my_values > 3]
+```
+```{r, test_array_predicate, opts.label = "test"}
+test_that("array_predicate works as expected", {
+ expect_equal(my_values[my_values > 3], Array$create(c(4L, 5L, NA)))
+})
+```
+
+### Discussion
+
+You can refer to items in an Array using the square brackets `[]` like you can
+an R vector.
+
+## Compute Mean/Min/Max, etc value of an Array
You want to calculate the mean, minimum, or maximum of values in an array.
@@ -73,7 +94,7 @@ If you find an S3 generic function which isn't implemented for Arrow objects
but you would like to be able to use, please
[open an issue on the project JIRA](https://issues.apache.org/jira/projects/ARROW/issues).
-## Counting occurrences of elements in an Array
+## Count occurrences of elements in an Array
You want to count repeated values in an Array.
@@ -105,7 +126,7 @@ directly on Arrow Array objects.
For example, the `value_counts()` function in the Arrow R package is loosely
equivalent to the base R function `table()`, which is not a generic function.
-## Applying arithmetic functions to Arrays.
+## Apply arithmetic functions to Arrays.
You want to use the various arithmetic operators on Array objects.
@@ -136,7 +157,7 @@ test_that("add_array_scalar works as expected", {
})
```
-## Calling Arrow compute functions directly on Arrays
+## Call Arrow compute functions directly on Arrays
You want to call an Arrow compute function directly on an Array.