summariseTopN: Truncate a dplyr summarisation using an "Other..." summary...

Description Usage Arguments Examples

View source: R/formatting.R

Description

Sometimes when you have a lot of results you want to show a short version of the results with an "Other..." category. This function performs a summarisation and allows you to specify the number of rows you want and something to sort the rows by. It will then give you strictly the top n results (ignoring ties) and group all the other results into a single summary row entitled "Other..."

Usage

1
summariseTopN(df, n, sortVar, label = "Other...", ...)

Arguments

df

- a grouped df - there must be some grouping for the summarise to return more than one row.

n

the number of rows to keep - the result will have one more row than this

sortVar

- the column containing the variable to sort by (syntax as in arrange(...))

label

- the name of the "Other..." row

...

- the arguments to the dplyr summarise(...)

Examples

1
diamonds %>% group_by(clarity) %>% summariseTopN(n=5, sortVar = desc(count), count = n(), avPrice = mean(price))

terminological/standard-print-output documentation built on July 18, 2021, 9:29 a.m.