.gen_data <- \(n_group, n_row, n_col_value, .seed = 1) {
groups <- seq_len(n_group) |>
rep_len(n_row) |>
as.character()
set.seed(.seed)
runif(n_row * n_col_value, min = 0, max = 100) |>
round() |>
matrix(ncol = n_col_value) |>
tibble::as_tibble(
.name_repair = \(x) paste0("col_value_", seq_len(n_col_value))
) |>
dplyr::mutate(col_group = groups, .before = 1)
}
.use_dplyr <-
function(.data) {
.data |>
dplyr::summarise(
value = sum(col_value_1, na.rm = TRUE),
.by = col_group
) |>
dplyr::arrange(col_group)
}
.use_dtplyr <-
function(.data) {
.data |>
dtplyr::lazy_dt() |>
dplyr::summarise(
value = sum(col_value_1, na.rm = TRUE),
.by = col_group
) |>
dplyr::arrange(col_group) |>
dplyr::collect()
}
.use_acero <-
function(.data) {
.data |>
arrow::as_arrow_table() |>
dplyr::summarise(
value = sum(col_value_1, na.rm = TRUE),
.by = col_group
) |>
dplyr::arrange(col_group) |>
dplyr::collect()
}
.use_duckplyr <-
function(.data) {
.data |>
duckplyr::as_duckplyr_df() |>
dplyr::summarise(
# na.rm は非対応
value = sum(col_value_1),
.by = col_group
) |>
dplyr::arrange(col_group)
}
.use_polars <-
function(.data) {
polars::as_polars_lf(.data)$group_by("col_group")$agg(
value = polars::pl$col("col_value_1")$sum()
)$sort("col_group")$collect() |>
tibble::as_tibble()
}