groupApply | R Documentation |
Apply a function to groups of data in an Andromeda table
groupApply(
tbl,
groupVariable,
fun,
...,
batchSize = 1e+05,
progressBar = FALSE,
safe = FALSE
)
tbl |
An |
groupVariable |
The variable to group by |
fun |
A function where the first argument is a data frame. |
... |
Additional parameters passed to fun. |
batchSize |
Number of rows fetched from the table at a time. This is not the number of rows to which the function will be applied. Included mostly for testing purposes. |
progressBar |
Show a progress bar? |
safe |
Create a copy of |
This function applies a function to groups of data. The groups are identified by unique values of
the groupVariable
, which must be a variable in the table.
Invisibly returns a list of objects, where each object is the output of the user-supplied function applied to a group.
batchApply()
andr <- andromeda(cars = cars)
fun <- function(x) {
return(tibble::tibble(speed = x$speed[1], meanDist = mean(x$dist)))
}
result <- groupApply(andr$cars, "speed", fun)
result <- bind_rows(result)
result
# # A tibble: 19 x 2
# speed meanDist
# <dbl> <dbl>
# 1 4 6
# 2 7 13
# 3 8 16
# ...
close(andr)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.