ianmcook commented on a change in pull request #1:
URL: https://github.com/apache/arrow-cookbook/pull/1#discussion_r674981383



##########
File path: r/content/manipulating_data.Rmd
##########
@@ -0,0 +1,66 @@
+# Manipulating Data
+
+## Computing Mean/Min/Max, etc value of an array
+
+Many base R functions such as `mean()`, `min()`, and `max()` have been mapped 
to their Arrow equivalents, and so can be called on Arrow Array objects in the 
same way.  They will return Arrow object themselves.
+
+```{r, array_mean_na}
+my_values <- Array$create(c(1:5, NA))
+mean(my_values, na.rm = TRUE)
+```
+```{r, test_array_mean_na, opts.label = "test"}
+test_that("array_mean_na works as expected", {
+  expect_equal(mean(my_values, na.rm = TRUE), Scalar$create(3))
+})
+```
+If you want to use an R function which does not have an Arrow mapping, you can 
use `as.vector()` to convert Arrow objects to base R vectors.
+
+```{r, fivenum}
+fivenum(as.vector(my_values))
+```
+```{r, test_fivenum, opts.label = "test"}
+test_that("fivenum works as expected", {
+  expect_equal(fivenum(as.vector(my_values)), 1:5)
+})
+```
+
+## Counting occurrences of elements in an array
+
+You can use `value_count()` to count elements in an Array.

Review comment:
       I think a preamble like this is helpful, but maybe a bit pedantic:
   ```suggestion
   Some functions in the Arrow R package do not have base R equivalents. In 
other cases, the base R equivalents are not generic functions so they cannot be 
called directly on Arrow Array objects.
   
   For example, the `value_count()` function in the Arrow R package is loosely 
equivalent to the base R function `table()`, which is not a generic function. 
To count the elements in an R vector, you can use `table()`; to count the 
elements in an Arrow Array, you can use `value_count()`.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to