| rp_summarize | R Documentation |
Aggregates a data frame by one or more groups, applying summary functions.
It translates R's dplyr::summarise syntax into a pandas .groupby().agg()
command.
rp_summarize(.data, ..., .by = NULL, table_name = NULL, return.as = "result")
.data |
An R data.frame or tibble. |
... |
Named summary expressions (e.g., |
.by |
A bare column name or |
table_name |
An optional character string. If provided, the generated Python code will replace the internal dataframe name with this string (e.g., |
return.as |
What to return: "result", "code", or "all". |
A data.frame with the summarized and grouped data.
if (reticulate::py_available(initialize = TRUE) &&
reticulate::py_module_available("pandas")) {
# Summarize by one group
rp_summarize(ggplot2::diamonds,
avg_price = mean(price),
.by = cut)
# Summarize by multiple groups and multiple functions
rp_summarize(ggplot2::diamonds,
avg_price = mean(price),
count = n(),
.by = c(cut, color))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.