Apply a function to groups of data in an Andromeda table

groupApply(
  tbl,
  groupVariable,
  fun,
  ...,
  batchSize = 1e+05,
  progressBar = FALSE,
  safe = FALSE
)

Arguments

tbl

An Andromeda table (or any other 'DBI' table).

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 tbl first? Allows writing to the same Andromeda as being read from.

Value

Invisibly returns a list of objects, where each object is the output of the user-supplied function applied to a group.

Details

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.

See also

Examples

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 × 2
#>    speed meanDist
#>    <dbl>    <dbl>
#>  1     4      6  
#>  2     7     13  
#>  3     8     16  
#>  4     9     10  
#>  5    10     26  
#>  6    11     22.5
#>  7    12     21.5
#>  8    13     35  
#>  9    14     50.5
#> 10    15     33.3
#> 11    16     36  
#> 12    17     40.7
#> 13    18     64.5
#> 14    19     50  
#> 15    20     50.4
#> 16    22     66  
#> 17    23     54  
#> 18    24     93.8
#> 19    25     85  
# # A tibble: 19 x 2 
# speed meanDist 
# <dbl> <dbl> 
# 1 4 6 
# 2 7 13 
# 3 8 16 
# ...

close(andr)